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:io.anserini.index.IndexWebCollection.java

static Deque<Path> discoverWarcFiles(Path p, final String suffix) {

    final Deque<Path> stack = new ArrayDeque<>();

    FileVisitor<Path> fv = new SimpleFileVisitor<Path>() {

        @Override//from  w  w w.j ava 2  s .  c  o m
        public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {

            Path name = file.getFileName();
            if (name != null && name.toString().endsWith(suffix))
                stack.add(file);
            return FileVisitResult.CONTINUE;
        }

        @Override
        public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) {
            if ("OtherData".equals(dir.getFileName().toString())) {
                LOG.info("Skipping: " + dir);
                return FileVisitResult.SKIP_SUBTREE;
            }
            return FileVisitResult.CONTINUE;
        }

        @Override
        public FileVisitResult visitFileFailed(Path file, IOException ioe) {
            LOG.error("Visiting failed for " + file.toString(), ioe);
            return FileVisitResult.SKIP_SUBTREE;
        }
    };

    try {
        Files.walkFileTree(p, fv);
    } catch (IOException e) {
        LOG.error("IOException during file visiting", e);
    }
    return stack;
}

From source file:com.facebook.buck.util.Escaper.java

public static String escapeAsBashString(Path path) {
    return escapeAsBashString(path.toString());
}

From source file:com.fizzed.rocker.compiler.RockerUtil.java

static public String pathToPackageName(Path path) {
    if (path == null) {
        return "";
    }/* w w w.j  av a2  s  .  c  o m*/
    // path.toString() uses File.seperator between components
    return path.toString().replace(File.separator, ".");
}

From source file:ch.devmine.javaparser.Main.java

private static void parseAsDirectory(Project project, HashMap<String, Package> packs, List<Language> languages,
        Language language, String arg) {
    File repoRoot = new File(arg);
    Path repoPath = repoRoot.toPath();

    FilesWalker fileWalker = new FilesWalker();
    try {//  w ww.j a  v a 2 s.  co  m
        Files.walkFileTree(repoPath, fileWalker);
    } catch (IOException ex) {
        Log.e(TAG, ex.getMessage());
    }

    String path = repoPath.toString();
    String name = path.substring(path.lastIndexOf("/") + 1);
    project.setName(name);

    for (String dir : fileWalker.getDirectories()) {
        dir = dir.replaceAll("\n", "");
        if (FileTypeFinder.search(dir, ".java")) {
            Package pack = new Package();
            String packName = dir.substring(dir.lastIndexOf("/") + 1);
            pack.setName(packName);
            pack.setPath(dir);
            packs.put(packName, pack);
        }
    }

    List<String> javaFiles = FileWalkerUtils.extractJavaFiles(fileWalker.getRegularFiles());
    for (String javaFile : javaFiles) {
        try {
            Parser parser = new Parser(javaFile, null);
            SourceFile sourceFile = new SourceFile();
            String packName = FileWalkerUtils.extractFolderName(javaFile);
            parseAndFillSourceFile(parser, sourceFile, javaFile, language, packs, packName);
        } catch (FileNotFoundException ex) {
            Log.e(TAG, ex.getMessage());
        }
    }

}

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

/**
 * Deletes a whole directory (recursively)
 * <p>//from w w  w.j  av a 2 s .  com
 * @param aDir
 *        a folder to be deleted (must not be null)
 * @throws IOException
 */
public static void deleteDirRecursive(Path aDir) throws IOException {
    if (aDir == null) {
        throw new IllegalArgumentException("aDir must not be null");
    }

    if (Files.notExists(aDir)) {
        return;
    }

    if (!Files.isDirectory(aDir)) {
        throw new IllegalArgumentException("given aDir is not a directory");
    }

    Files.walkFileTree(aDir, new SimpleFileVisitor<Path>() {
        /**
         * @see java.nio.file.SimpleFileVisitor#visitFileFailed(java.lang.Object, java.io.IOException)
         */
        @Override
        public FileVisitResult visitFileFailed(Path aFile, IOException aExc) throws IOException {
            if ("System Volume Information".equals((aFile.getFileName().toString()))) {
                return FileVisitResult.SKIP_SUBTREE;
            }

            throw aExc;
        }

        /**
         * @see java.nio.file.SimpleFileVisitor#preVisitDirectory(java.lang.Object, java.nio.file.attribute.BasicFileAttributes)
         */
        @Override
        public FileVisitResult preVisitDirectory(Path aFile, BasicFileAttributes aAttrs) throws IOException {
            if ("System Volume Information".equals((aFile.getFileName()))) {
                return FileVisitResult.SKIP_SUBTREE;
            }

            return FileVisitResult.CONTINUE;
        }

        @Override
        public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
            Files.delete(file);
            return FileVisitResult.CONTINUE;
        }

        @Override
        public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
            if (dir.isAbsolute() && dir.getRoot().equals(dir)) {
                myLog.debug("root cannot be deleted: " + dir.toString());
                return FileVisitResult.CONTINUE;
            }

            Files.delete(dir);
            return FileVisitResult.CONTINUE;
        }

    });
}

From source file:com.eqbridges.vertx.VerticleModuleMojo.java

private static void validate(Path... paths) {
    for (Path path : paths) {
        requireNonNull(path);/*from   w ww .  j  a  va2 s  . c  o  m*/
        if (!isDirectory(path)) {
            throw new IllegalArgumentException(String.format("%s is not a directory", path.toString()));
        }
    }
}

From source file:com.facebook.buck.util.Escaper.java

/**
 * Escapes forward slashes in a Path as a String that is safe to consume with other tools (such
 * as gcc).  On Unix systems, this is equivalent to {@link java.nio.file.Path Path.toString()}.
 * @param path the Path to escape/*from  w  ww. ja v a  2  s.  c om*/
 * @return the escaped Path
 */
public static String escapePathForCIncludeString(Path path) {
    if (File.separatorChar != '\\') {
        return path.toString();
    }
    StringBuilder result = new StringBuilder();
    if (path.startsWith(File.separator)) {
        result.append("\\\\");
    }
    for (Iterator<Path> iterator = path.iterator(); iterator.hasNext();) {
        result.append(iterator.next());
        if (iterator.hasNext()) {
            result.append("\\\\");
        }
    }
    if (path.getNameCount() > 0 && path.endsWith(File.separator)) {
        result.append("\\\\");
    }
    return result.toString();
}

From source file:au.org.ands.vocabs.toolkit.utils.ToolkitFileUtils.java

/** Get the full path of the backup directory used to store all
 * backup data for a project./*w  ww. j av  a  2s.  c om*/
 * @param projectId The project ID. For now, this will be a PoolParty
 * project ID.
 * @return The full path of the directory used to store the
 * vocabulary data.
 */
public static String getBackupPath(final String projectId) {
    Path path = Paths.get(ToolkitConfig.BACKUP_FILES_PATH).resolve(makeSlug(projectId));
    return path.toString();
}

From source file:de.prozesskraft.pkraft.Waitinstance.java

/**
 * ermittelt alle process binaries innerhalb eines directory baumes
 * @param pathScandir// w w  w.j a va2s . c  o m
 * @return
 */
private static String[] getProcessBinaries(String pathScandir) {
    final ArrayList<String> allProcessBinaries = new ArrayList<String>();

    // den directory-baum durchgehen und fuer jeden eintrag ein entity erstellen
    try {
        Files.walkFileTree(Paths.get(pathScandir), new FileVisitor<Path>() {
            // called after a directory visit is complete
            public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
                return FileVisitResult.CONTINUE;
            }

            // called before a directory visit
            public FileVisitResult preVisitDirectory(Path walkingDir, BasicFileAttributes attrs)
                    throws IOException {
                return FileVisitResult.CONTINUE;
            }

            // called for each file visited. the basic file attributes of the file are also available
            public FileVisitResult visitFile(Path walkingFile, BasicFileAttributes attrs) throws IOException {
                // ist es ein process.pmb file?
                if (walkingFile.endsWith("process.pmb")) {
                    allProcessBinaries.add(new java.io.File(walkingFile.toString()).getAbsolutePath());
                }

                return FileVisitResult.CONTINUE;
            }

            // called for each file if the visit failed
            public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
                return FileVisitResult.CONTINUE;
            }

        });
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return allProcessBinaries.toArray(new String[allProcessBinaries.size()]);
}

From source file:au.org.ands.vocabs.toolkit.utils.ToolkitFileUtils.java

/** Get the full path of the temporary directory used to store all
 * harvested data for metadata extraction for a PoolParty vocabulary.
 * @param projectId The PoolParty projectId.
 * @return The full path of the directory used to store the
 * vocabulary data./*  www  . j av a  2s . com*/
 */
public static String getMetadataOutputPath(final String projectId) {
    Path path = Paths.get(ToolkitConfig.METADATA_TEMP_FILES_PATH).resolve(makeSlug(projectId));
    return path.toString();
}