Example usage for java.io File toString

List of usage examples for java.io File toString

Introduction

In this page you can find the example usage for java.io File toString.

Prototype

public String toString() 

Source Link

Document

Returns the pathname string of this abstract pathname.

Usage

From source file:io.bci.BitcoinSTLGenerator.java

private static void saveKeys(ByteArrayOutputStream pub, ByteArrayOutputStream priv) {
    String pubFileName = getFilePrefix() + "pubKey";
    String privFileName = getFilePrefix() + "privKey";

    File pubFile = new File("images/" + pubFileName + ".png");
    File privFile = new File("images/" + privFileName + ".png");

    // Saving public key first
    try {//from   w ww  .  j  av a  2 s .c o m
        FileOutputStream fout = new FileOutputStream(pubFile);

        fout.write(pub.toByteArray());

        fout.flush();
        fout.close();

    } catch (FileNotFoundException e) {
        System.out.println("ERROR: Public key file creation failed: " + pubFile.toString());
        e.printStackTrace();
    } catch (IOException e) {
        System.out.println("ERROR: Public key file read/write failed: " + pubFile.toString());
        e.printStackTrace();
    } finally {
        System.out.println("Public key file created: " + pubFile.toString());
    }

    // Then saving the private key
    try {
        FileOutputStream fout = new FileOutputStream(privFile);

        fout.write(priv.toByteArray());

        fout.flush();
        fout.close();

    } catch (FileNotFoundException e) {
        System.out.println("ERROR: Private key file creation failed: " + privFile.toString());
        e.printStackTrace();
    } catch (IOException e) {
        System.out.println("ERROR: Private key file read/write failed: " + privFile.toString());
        e.printStackTrace();
    } finally {
        System.out.println("Private key file created: " + privFile.toString());
    }

    // Checking for noStl flag. If set, don't create stl files
    if (!noStl) {
        drawSTL(pubFile, pubFileName);
        drawSTL(privFile, privFileName);
    }
}

From source file:io.bci.BitcoinSTLGenerator.java

private static void saveKeys(ByteArrayOutputStream pub, ByteArrayOutputStream priv, int index) {
    String pubFileName = getFilePrefix() + "pubKey_" + index;
    String privFileName = getFilePrefix() + "privKey_" + index;

    File pubFile = new File("images/" + pubFileName + ".png");
    File privFile = new File("images/" + privFileName + ".png");

    // Saving public key first
    try {/*from w  w w . j  a  v a 2 s.  c o m*/
        FileOutputStream fout = new FileOutputStream(pubFile);

        fout.write(pub.toByteArray());

        fout.flush();
        fout.close();

    } catch (FileNotFoundException e) {
        System.out.println("ERROR: Public key file creation failed: " + pubFile.toString());
        e.printStackTrace();
    } catch (IOException e) {
        System.out.println("ERROR: Public key file read/write failed: " + pubFile.toString());
        e.printStackTrace();
    } finally {
        System.out.println("Public key file created: " + pubFile.toString());
    }

    // Then saving the private key
    try {
        FileOutputStream fout = new FileOutputStream(privFile);

        fout.write(priv.toByteArray());

        fout.flush();
        fout.close();

    } catch (FileNotFoundException e) {
        System.out.println("ERROR: Private key file creation failed: " + privFile.toString());
        e.printStackTrace();
    } catch (IOException e) {
        System.out.println("ERROR: Private key file read/write failed: " + privFile.toString());
        e.printStackTrace();
    } finally {
        System.out.println("Private key file created: " + privFile.toString());
    }

    // Checking for noStl flag. If set, don't create stl files
    if (!noStl) {
        drawSTL(pubFile, pubFileName);
        drawSTL(privFile, privFileName);
    }
}

From source file:com.apatar.ui.Actions.java

public static void openProject(JFrame frame, JWorkPane workPane) {
    fileChooser.setMultiSelectionEnabled(false);
    fileChooser.setFileFilter(FF);/*from w  w w .  j a v  a 2  s .  com*/

    int returnValue = fileChooser.showOpenDialog(frame);
    if (returnValue == JFileChooser.APPROVE_OPTION) {
        File fileSrc = fileChooser.getSelectedFile();
        ApplicationData.COUNT_INIT_ERROR = 0;

        // ReadWriteXMLData.loadDateAndTimeSettings(fileSrc.toString());
        ReadWriteXMLDataUi rwXMLdata = new ReadWriteXMLDataUi();
        try {
            ApatarUiMain.MAIN_FRAME.setTitle(String.format(JApatarMainUIFrame.FRAME_TITLE,
                    rwXMLdata.readXMLData(fileSrc.toString(), ApplicationData.getProject()) + " - "));
        } catch (Exception e) {
            e.printStackTrace();
        }

        if (ApplicationData.COUNT_INIT_ERROR > 0) {
            JOptionPane.showMessageDialog(ApatarUiMain.MAIN_FRAME,
                    "An error occured while opening the DataMap: Uninitialized properties were found.\nPlease, check node(-s) configuration.");
        }
        UiUtils.updatePane(ApplicationData.getProject(), workPane);
        ApplicationData.PROJECT_PATH = fileSrc.getPath();
    }
}

From source file:net.yacy.yacy.java

/**
 * @see File#mkdir()/*w ww. j ava  2s.  co  m*/
 * @param path
 */
private static void mkdirIfNeseccary(final File path) {
    if (!(path.exists()))
        if (!path.mkdir())
            ConcurrentLog.warn("STARTUP", "could not create directory " + path.toString());
}

From source file:net.yacy.yacy.java

/**
 * @see File#mkdirs()/*  ww w.  j  av  a 2 s. c om*/
 * @param path
 */
public static void mkdirsIfNeseccary(final File path) {
    if (!(path.exists()))
        if (!path.mkdirs())
            ConcurrentLog.warn("STARTUP", "could not create directories " + path.toString());
}

From source file:hdfs.FileUtil.java

/**
 * Given a Tar File as input it will untar the file in a the untar directory
 * passed as the second parameter//from  www.ja v a2s .  c o m
 * 
 * This utility will untar ".tar" files and ".tar.gz","tgz" files.
 *  
 * @param inFile The tar file as input. 
 * @param untarDir The untar directory where to untar the tar file.
 * @throws IOException
 */
public static void unTar(File inFile, File untarDir) throws IOException {
    if (!untarDir.mkdirs()) {
        if (!untarDir.isDirectory()) {
            throw new IOException("Mkdirs failed to create " + untarDir);
        }
    }

    StringBuffer untarCommand = new StringBuffer();
    boolean gzipped = inFile.toString().endsWith("gz");
    if (gzipped) {
        untarCommand.append(" gzip -dc '");
        untarCommand.append(FileUtil.makeShellPath(inFile));
        untarCommand.append("' | (");
    }
    untarCommand.append("cd '");
    untarCommand.append(FileUtil.makeShellPath(untarDir));
    untarCommand.append("' ; ");
    untarCommand.append("tar -xf ");

    if (gzipped) {
        untarCommand.append(" -)");
    } else {
        untarCommand.append(FileUtil.makeShellPath(inFile));
    }
    String[] shellCmd = { "bash", "-c", untarCommand.toString() };
    ShellCommandExecutor shexec = new ShellCommandExecutor(shellCmd);
    shexec.execute();
    int exitcode = shexec.getExitCode();
    if (exitcode != 0) {
        throw new IOException(
                "Error untarring file " + inFile + ". Tar process exited with exit code " + exitcode);
    }
}

From source file:ffx.utilities.StringUtils.java

/**
 * Returns the file name of a temporary copy of <code>input</code> content.
 *
 * @param input a {@link java.io.InputStream} object.
 * @param name a {@link java.lang.String} object.
 * @param suffix a {@link java.lang.String} object.
 * @return a {@link java.lang.String} object.
 * @throws java.io.IOException if any./*from  w  ww . java 2 s  . c o m*/
 */
public static String copyInputStreamToTmpFile(final InputStream input, String name, final String suffix)
        throws IOException {
    File tmpFile = null;
    try {
        name = "ffx." + name + ".";
        tmpFile = File.createTempFile(name, suffix);
    } catch (Exception e) {
        System.out.println(" Could not extract a Force Field X library.");
        System.err.println(e.toString());
        System.exit(-1);
    }

    tmpFile.deleteOnExit();
    OutputStream output = null;
    try {
        output = new BufferedOutputStream(new FileOutputStream(tmpFile));
        byte[] buffer = new byte[8192];
        int size;
        while ((size = input.read(buffer)) != -1) {
            output.write(buffer, 0, size);
        }
    } finally {
        if (input != null) {
            input.close();
        }
        if (output != null) {
            output.close();
        }
    }

    return tmpFile.toString();
}

From source file:com.net2plan.gui.utils.NoRunnableCodeFound.java

/**
 * Default constructor./* ww  w  .  j  a va2s  .  c  o m*/
 *
 * @param f        File where runnable code should be found
 * @param _classes Set of admissible classes for runnable code
 * @since 0.3.1
 */
public NoRunnableCodeFound(File f, Set<Class<? extends IExternal>> _classes) {
    super(String.format(TEMPLATE, f.toString(), StringUtils.join(toString(_classes), ", ")));
}

From source file:com.symbian.driver.core.ResourceLoader.java

/**
 * Loads TDv1 XML files.//from   w  ww  . j  a v  a  2  s .  c o  m
 * 
 * @param aXmlRoot The location of the XML root for TDv1.
 * @param aRootAddress The URI to the Execute to load.
 * @return The task corresponding to the URI specfied in the XML Root directory.
 * @throws ParseException If there was a problem with getting the configuration.
 * @throws FileNotFoundException IF the XML root directory is invalid.
 * @throws IOException If the URI or XML root directory is invalid.
 */
public static Task loadOldXml(File aXmlRoot, URI aRootAddress)
        throws ParseException, FileNotFoundException, IOException {
    LOGGER.info("Importing Old TestDriver v1 XML at: " + aXmlRoot.getAbsolutePath());

    // Create Document Root
    DocumentRoot lDocumentRoot = DriverFactory.eINSTANCE.createDocumentRoot();
    // Register the factory
    Driver lDriver = DriverFactory.eINSTANCE.createDriver();
    // Import Old XML to new XML
    lDriver.setTask(new FrameworkGenerator(aXmlRoot).buildEmfModel());
    lDocumentRoot.setDriver(lDriver);

    File lSaveFile = null;
    if (aXmlRoot.isDirectory()) {
        lSaveFile = new File(aXmlRoot.getCanonicalPath() + File.separator + aXmlRoot.getName() + ".driver");
    } else if (aXmlRoot.isFile()) {
        lSaveFile = new File(aXmlRoot.toString().replaceAll("\\.xml", ".driver"));
    }

    DriverResourceImpl lResource = (DriverResourceImpl) iResourceSet
            .createResource(URI.createFileURI(lSaveFile.getAbsolutePath()));
    lResource.getContents().add(lDocumentRoot);

    Map lSaveOptions = new HashMap();
    lSaveOptions.put(XMLResource.OPTION_ENCODING, "UTF-8");

    lResource.save(new FileOutputStream(lSaveFile), lSaveOptions);
    LOGGER.info("Created TestDriver v2 XML file at: " + lSaveFile.getCanonicalPath());

    if (aRootAddress != null) {
        String lTempFragement = aRootAddress.toString();
        aRootAddress = URI.createFileURI(lSaveFile.getCanonicalPath());
        aRootAddress = aRootAddress
                .appendFragment(lTempFragement.charAt(0) == '#' ? lTempFragement.substring(1) : lTempFragement);

        TDConfig.getInstance().setPreferenceURI(TDConfig.ENTRY_POINT_ADDRESS, aRootAddress);

        ExtendedDriverValidator.validator(lResource);

        return lResource.getTask(aRootAddress.fragment());
    }

    return ((DocumentRoot) lResource.getContents().get(0)).getDriver().getTask();
}

From source file:io.bitsquare.common.util.Utilities.java

public static void openDirectory(File directory) throws IOException {
    if (!isLinux() && Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.OPEN)) {
        Desktop.getDesktop().open(directory);
    } else {//from  w  ww .ja v a2 s . c o  m
        // Maybe Application.HostServices works in those cases?
        // HostServices hostServices = getHostServices();
        // hostServices.showDocument(uri.toString());

        // On Linux Desktop is poorly implemented.
        // See https://stackoverflow.com/questions/18004150/desktop-api-is-not-supported-on-the-current-platform
        if (!DesktopUtil.open(directory))
            throw new IOException("Failed to open directory: " + directory.toString());
    }
}