Example usage for java.nio.file Path toString

List of usage examples for java.nio.file Path toString

Introduction

In this page you can find the example usage for java.nio.file Path toString.

Prototype

String toString();

Source Link

Document

Returns the string representation of this path.

Usage

From source file:ch.bender.evacuate.Runner.java

/**
 * visit//from w  w  w . jav a2 s.  c  o m
 * <p>
 * @param aPath
 * @return
 */
private FileVisitResult visit(Path aPath) {
    if (isExcluded(aPath)) {
        myLog.debug("Skip because on exclude list: " + aPath.toString());

        if (Files.isDirectory(aPath)) {
            myExclusionDirCount++;
        } else {
            myExclusionFileCount++;
        }

        return FileVisitResult.SKIP_SUBTREE;
    }

    Path subDirToBackupRoot = myBackupDir.relativize(aPath);
    Path origPendant = myOrigDir.resolve(subDirToBackupRoot);

    if (Files.notExists(origPendant)) {
        evacuate(aPath);

        if (Files.isDirectory(aPath)) {
            myEvacuationDirCount++;
            return FileVisitResult.SKIP_SUBTREE;
        }

        // else is file:
        myEvacuationFileCount++;
        return FileVisitResult.CONTINUE;
    }

    return FileVisitResult.CONTINUE;
}

From source file:com.splicemachine.storage.HNIOFileSystem.java

@Override
public void touchFile(Path path) throws IOException {
    if (!fs.createNewFile(toHPath(path))) {
        throw new FileAlreadyExistsException(path.toString());
    }//from  ww w.j  a  v a  2 s. c  o  m
}

From source file:ffx.potential.utils.PotentialsFileOpener.java

/**
 * At present, parses the PDB, XYZ, INT, or ARC file from the constructor
 * and creates MolecularAssembly and properties objects.
 *//*from   ww  w  .  j  a v  a 2  s .co m*/
@Override
public void run() {
    int numFiles = allFiles.length;
    for (int i = 0; i < numFiles; i++) {
        File fileI = allFiles[i];
        Path pathI = allPaths[i];
        MolecularAssembly assembly = new MolecularAssembly(pathI.toString());
        assembly.setFile(fileI);
        CompositeConfiguration properties = Keyword.loadProperties(fileI);
        ForceFieldFilter forceFieldFilter = new ForceFieldFilter(properties);
        ForceField forceField = forceFieldFilter.parse();
        String patches[] = properties.getStringArray("patch");
        for (String patch : patches) {
            logger.info(" Attempting to read force field patch from " + patch + ".");
            CompositeConfiguration patchConfiguration = new CompositeConfiguration();
            try {
                patchConfiguration.addProperty("propertyFile", fileI.getCanonicalPath());
            } catch (IOException e) {
                logger.log(Level.INFO, " Error loading {0}.", patch);
            }
            patchConfiguration.addProperty("parameters", patch);
            forceFieldFilter = new ForceFieldFilter(patchConfiguration);
            ForceField patchForceField = forceFieldFilter.parse();
            forceField.append(patchForceField);
            if (RotamerLibrary.addRotPatch(patch)) {
                logger.info(String.format(" Loaded rotamer definitions from patch %s.", patch));
            }
        }
        assembly.setForceField(forceField);
        if (new PDBFileFilter().acceptDeep(fileI)) {
            filter = new PDBFilter(fileI, assembly, forceField, properties);
        } else if (new XYZFileFilter().acceptDeep(fileI)) {
            filter = new XYZFilter(fileI, assembly, forceField, properties);
        } else if (new INTFileFilter().acceptDeep(fileI) || new ARCFileFilter().accept(fileI)) {
            filter = new INTFilter(fileI, assembly, forceField, properties);
        } else {
            throw new IllegalArgumentException(
                    String.format(" File %s could not be recognized as a valid PDB, XYZ, INT, or ARC file.",
                            pathI.toString()));
        }
        if (filter.readFile()) {
            if (!(filter instanceof PDBFilter)) {
                Utilities.biochemistry(assembly, filter.getAtomList());
            }
            filter.applyAtomProperties();
            assembly.finalize(true, forceField);
            //ForceFieldEnergy energy = new ForceFieldEnergy(assembly, filter.getCoordRestraints());
            ForceFieldEnergy energy;
            if (nThreads > 0) {
                energy = new ForceFieldEnergy(assembly, filter.getCoordRestraints(), nThreads);
            } else {
                energy = new ForceFieldEnergy(assembly, filter.getCoordRestraints());
            }
            assembly.setPotential(energy);
            assemblies.add(assembly);
            propertyList.add(properties);

            if (filter instanceof PDBFilter) {
                PDBFilter pdbFilter = (PDBFilter) filter;
                List<Character> altLocs = pdbFilter.getAltLocs();
                if (altLocs.size() > 1 || altLocs.get(0) != ' ') {
                    StringBuilder altLocString = new StringBuilder("\n Alternate locations found [ ");
                    for (Character c : altLocs) {
                        // Do not report the root conformer.
                        if (c == ' ') {
                            continue;
                        }
                        altLocString.append(format("(%s) ", c));
                    }
                    altLocString.append("]\n");
                    logger.info(altLocString.toString());
                }

                /**
                 * Alternate conformers may have different chemistry, so
                 * they each need to be their own MolecularAssembly.
                 */
                for (Character c : altLocs) {
                    if (c.equals(' ') || c.equals('A')) {
                        continue;
                    }
                    MolecularAssembly newAssembly = new MolecularAssembly(pathI.toString());
                    newAssembly.setForceField(assembly.getForceField());
                    pdbFilter.setAltID(newAssembly, c);
                    pdbFilter.clearSegIDs();
                    if (pdbFilter.readFile()) {
                        String fileName = assembly.getFile().getAbsolutePath();
                        newAssembly.setName(FilenameUtils.getBaseName(fileName) + " " + c);
                        filter.applyAtomProperties();
                        newAssembly.finalize(true, assembly.getForceField());
                        //energy = new ForceFieldEnergy(newAssembly, filter.getCoordRestraints());
                        if (nThreads > 0) {
                            energy = new ForceFieldEnergy(assembly, filter.getCoordRestraints(), nThreads);
                        } else {
                            energy = new ForceFieldEnergy(assembly, filter.getCoordRestraints());
                        }
                        newAssembly.setPotential(energy);
                        assemblies.add(newAssembly);
                    }
                }
            }
        } else {
            logger.warning(String.format(" Failed to read file %s", fileI.toString()));
        }
    }
    activeAssembly = assemblies.get(0);
    activeProperties = propertyList.get(0);
}

From source file:net.es.nsi.topology.translator.Options.java

/**
 * Processes the "configfile" command line and system property option.
 *
 * @param cmd Commands entered by the user.
 * @param configdir The application configuration directory.
 * @return The configuration file path.//  w ww .  j  a v a 2  s. c  o  m
 * @throws IOException
 */
private String getConfigFile(CommandLine cmd) throws IOException {
    String file = System.getProperty(Properties.SYSTEM_PROPERTY_CONFIGFILE);
    file = cmd.getOptionValue(ARGNAME_CONFIGFILE, file);

    Path path;
    if (Strings.isNullOrEmpty(file)) {
        path = Paths.get(basedir, DEFAULT_CONFIGFILE);
    } else {
        path = Paths.get(file);
        if (!path.isAbsolute()) {
            path = Paths.get(basedir, path.toString());
        }
    }

    try {
        file = path.toRealPath().toString();
    } catch (IOException ex) {
        System.err.println("Error: Configuration file not found " + path.toString() + "\n");
        throw ex;
    }

    return file;
}

From source file:com.evolveum.midpoint.tools.schemadist.SchemaDistMojo.java

private void serializeXml(Document dom, Path filePath, File workDir, File outDir)
        throws MojoFailureException, MojoExecutionException {
    Path fileRelPath = workDir.toPath().relativize(filePath);
    File outFile = new File(outDir, fileRelPath.toString());
    initializeOutDir(outFile.getParentFile());
    try {/*from w  ww  .  ja  v a 2s .  c  o  m*/
        DOMUtil.serializeDOMToFile(dom, outFile);
    } catch (TransformerFactoryConfigurationError | TransformerException e) {
        throw new MojoExecutionException(
                "Error serializing modified file " + fileRelPath + " to XML: " + e.getMessage(), e);
    }
}

From source file:com.google.cloud.tools.managedcloudsdk.install.ZipExtractorProvider.java

@Override
public void extract(Path archive, Path destination, ProgressListener progressListener) throws IOException {

    progressListener.start("Extracting archive: " + archive.getFileName(), ProgressListener.UNKNOWN);

    String canonicalDestination = destination.toFile().getCanonicalPath();

    // Use ZipFile instead of ZipArchiveInputStream so that we can obtain file permissions
    // on unix-like systems via getUnixMode(). ZipArchiveInputStream doesn't have access to
    // all the zip file data and will return "0" for any call to getUnixMode().
    try (ZipFile zipFile = new ZipFile(archive.toFile())) {
        // TextProgressBar progressBar = textBarFactory.newProgressBar(messageListener, count);
        Enumeration<ZipArchiveEntry> zipEntries = zipFile.getEntries();
        while (zipEntries.hasMoreElements()) {
            ZipArchiveEntry entry = zipEntries.nextElement();
            Path entryTarget = destination.resolve(entry.getName());

            String canonicalTarget = entryTarget.toFile().getCanonicalPath();
            if (!canonicalTarget.startsWith(canonicalDestination + File.separator)) {
                throw new IOException("Blocked unzipping files outside destination: " + entry.getName());
            }//from   w  w  w. j a v a 2 s. c  om

            progressListener.update(1);
            logger.fine(entryTarget.toString());

            if (entry.isDirectory()) {
                if (!Files.exists(entryTarget)) {
                    Files.createDirectories(entryTarget);
                }
            } else {
                if (!Files.exists(entryTarget.getParent())) {
                    Files.createDirectories(entryTarget.getParent());
                }
                try (OutputStream out = new BufferedOutputStream(Files.newOutputStream(entryTarget))) {
                    try (InputStream in = zipFile.getInputStream(entry)) {
                        IOUtils.copy(in, out);
                        PosixFileAttributeView attributeView = Files.getFileAttributeView(entryTarget,
                                PosixFileAttributeView.class);
                        if (attributeView != null) {
                            attributeView
                                    .setPermissions(PosixUtil.getPosixFilePermissions(entry.getUnixMode()));
                        }
                    }
                }
            }
        }
    }
    progressListener.done();
}

From source file:com.highcharts.export.controller.ExportController.java

public String createRandomFileName(String extension) {
    Path path = Paths.get(TempDir.outputDir.toString(),
            RandomStringUtils.randomAlphanumeric(8) + "." + extension);
    return path.toString();
}

From source file:com.bekwam.resignator.commands.UnsignCommand.java

private Path copyJAR(File sourceJarFile) throws CommandExecutionException {
    Path workingJarFile = Paths.get(tempDir.toString(), sourceJarFile.getName());

    try {/*from w w  w .  j av  a2 s.com*/
        Files.copy(Paths.get(sourceJarFile.getAbsolutePath()), workingJarFile);
    } catch (IOException exc) {
        String msg = String.format("can't copy %s to %s", sourceJarFile.getAbsolutePath(),
                workingJarFile.toString());
        logger.error(msg, exc);
        throw new CommandExecutionException(msg);
    }
    return workingJarFile;
}

From source file:dk.dma.msiproxy.common.repo.ThumbnailService.java

/**
 * Creates a thumbnail for the image file using libvips
 *
 * @param file      the image file/*from   w w w  .j a  v a2 s.  c  om*/
 * @param thumbFile the resulting thumbnail file
 * @param size      the size of the thumbnail
 */
private void createThumbnailUsingVips(Path file, Path thumbFile, IconSize size) throws IOException {

    try {

        // Example command: vipsthumbnail -s 64 -p bilinear -o thumb.png image2.jpg
        final Process proc = new ProcessBuilder(vipsCmd, "-s", String.valueOf(size.getSize()), "-p", "bilinear",
                "-o", thumbFile.toString(), file.toString()).directory(new File(System.getProperty("user.dir")))
                        .inheritIO().start();

        BufferedReader br = new BufferedReader(new InputStreamReader(proc.getInputStream()));
        String line;
        while ((line = br.readLine()) != null) {
            log.debug(line);
        }

        //Wait to get exit value
        int exitValue = proc.waitFor();
        log.debug("Exit Value is " + exitValue);

        // Update the timestamp of the thumbnail file to match the change date of the image file
        Files.setLastModifiedTime(thumbFile, Files.getLastModifiedTime(file));

    } catch (IOException | InterruptedException e) {
        log.error("Error creating thumbnail for image " + file, e);
        throw new IOException(e);
    }
}

From source file:info.pancancer.arch3.worker.WorkerRunnable.java

/**
 * Write the content of the job object to an INI file which will be used by the workflow.
 *
 * @param job//  w ww .ja va  2  s  .  c o m
 *            - the job object which must contain a HashMap, which will be used to write an INI file.
 * @return A Path object pointing to the new file will be returned.
 * @throws IOException
 */
private Path writeINIFile(Job job) throws IOException {
    log.info("INI is: " + job.getIniStr());
    EnumSet<PosixFilePermission> perms = EnumSet.of(PosixFilePermission.OWNER_READ,
            PosixFilePermission.OWNER_WRITE, PosixFilePermission.OWNER_EXECUTE, PosixFilePermission.GROUP_READ,
            PosixFilePermission.GROUP_WRITE, PosixFilePermission.OTHERS_READ, PosixFilePermission.OTHERS_WRITE);
    FileAttribute<?> attrs = PosixFilePermissions.asFileAttribute(perms);
    Path pathToINI = Files.createTempFile("seqware_", ".ini", attrs);
    log.info("INI file: " + pathToINI.toString());
    try (BufferedWriter bw = new BufferedWriter(
            new OutputStreamWriter(new FileOutputStream(pathToINI.toFile()), StandardCharsets.UTF_8))) {
        bw.write(job.getIniStr());
        bw.flush();
    }
    return pathToINI;
}