Example usage for java.nio.file FileVisitResult CONTINUE

List of usage examples for java.nio.file FileVisitResult CONTINUE

Introduction

In this page you can find the example usage for java.nio.file FileVisitResult CONTINUE.

Prototype

FileVisitResult CONTINUE

To view the source code for java.nio.file FileVisitResult CONTINUE.

Click Source Link

Document

Continue.

Usage

From source file:desktopsearch.WatchDir.java

/**
 * Register the given directory, and all its sub-directories, with the
 * WatchService./*from w  w  w.jav a  2  s. co  m*/
 */
private void registerAll(final Path start) {
    // register directory and sub-directories
    try {
        Files.walkFileTree(start, new SimpleFileVisitor<Path>() {
            @Override
            public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
                register(dir);
                return FileVisitResult.CONTINUE;
            }
        });
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:fi.hsl.parkandride.ExportQTypes.java

private static void deleteOldQTypes(Path packageDir) throws IOException {
    Files.walkFileTree(packageDir, new SimpleFileVisitor<Path>() {
        @Override/*from  w  w  w  .  j  a va2 s .  co m*/
        public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IOException {
            if (path.getFileName().toString().startsWith(NAME_PREFIX)) {
                Files.delete(path);
            }
            return FileVisitResult.CONTINUE;
        }
    });
}

From source file:io.crate.testing.Utils.java

public static void deletePath(Path path) throws IOException {
    Files.walkFileTree(path, new SimpleFileVisitor<Path>() {
        @Override//from  w  ww  . ja  v  a2 s  . c  om
        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 {
            Files.delete(dir);
            return FileVisitResult.CONTINUE;
        }

    });
}

From source file:se.trixon.toolbox.checksum.FileVisitor.java

@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
    if (Thread.interrupted()) {
        mInterrupted = true;//from   w ww. j  a va2s . c  o m
        return FileVisitResult.TERMINATE;
    }

    Toolbox.setStatusText(dir.toFile().getAbsolutePath(), StatusDisplayer.IMPORTANCE_ERROR_HIGHLIGHT);

    String[] filePaths = dir.toFile().list();

    if (filePaths != null && filePaths.length > 0) {
        for (String fileName : filePaths) {
            File file = new File(dir.toFile(), fileName);
            if (file.isFile()) {
                mRelativePaths.add(getRelativePath(file, mBaseDir));
            }
        }
    }

    return FileVisitResult.CONTINUE;
}

From source file:org.apache.openaz.xacml.pdp.test.conformance.ConformanceTestSet.java

public static ConformanceTestSet loadDirectory(File fileDir) throws IOException {
    final Map<String, ConformanceTest> mapConformanceTests = new HashMap<String, ConformanceTest>();

    Files.walkFileTree(fileDir.toPath(), new FileVisitor<Path>() {
        @Override//from w w w . jav a  2  s .  co m
        public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
            logger.info("Scanning directory " + dir.getFileName());
            return FileVisitResult.CONTINUE;
        }

        @Override
        public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
            File fileVisited = file.toFile();
            String fileName = fileVisited.getName();
            if (fileName.endsWith(".xml") || fileName.endsWith(".properties")) {
                String testName = getTestName(fileVisited);
                if (testName != null) {
                    ConformanceTest conformanceTest = mapConformanceTests.get(testName);
                    if (conformanceTest == null) {
                        logger.info("Added test " + testName);
                        conformanceTest = new ConformanceTest(testName);
                        mapConformanceTests.put(testName, conformanceTest);
                    }
                    if (fileName.endsWith("Policy.xml")) {
                        conformanceTest.getRepository().addRootPolicy(fileVisited);
                    } else if (fileName.endsWith("Repository.properties")) {
                        conformanceTest.getRepository().load(fileVisited);
                    } else if (fileName.endsWith("Request.xml")) {
                        conformanceTest.setRequest(fileVisited);
                    } else if (fileName.endsWith("Response.xml")) {
                        conformanceTest.setResponse(fileVisited);
                    }
                }
            }
            return FileVisitResult.CONTINUE;
        }

        @Override
        public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
            logger.warn("Skipped " + file.getFileName());
            return FileVisitResult.CONTINUE;
        }

        @Override
        public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
            return FileVisitResult.CONTINUE;
        }
    });

    /*
     * Sort the keyset and pull out the tests that have the required components
     */
    List<String> listTestNames = new ArrayList<String>();
    listTestNames.addAll(mapConformanceTests.keySet());
    Collections.sort(listTestNames);

    ConformanceTestSet conformanceTestSet = new ConformanceTestSet();
    Iterator<String> iterTestNames = listTestNames.iterator();
    while (iterTestNames.hasNext()) {
        ConformanceTest conformanceTest = mapConformanceTests.get(iterTestNames.next());
        if (conformanceTest.isComplete()) {
            conformanceTestSet.addConformanceTest(conformanceTest);
            logger.debug("Added conformance test " + conformanceTest.getTestName());
        } else {
            logger.warn("Incomplete conformance test " + conformanceTest.getTestName());
        }
    }

    return conformanceTestSet;

}

From source file:nl.salp.warcraft4j.config.PropertyWarcraft4jConfigTest.java

private static void delete(Path directory) throws Exception {
    Files.walkFileTree(directory, new SimpleFileVisitor<Path>() {
        @Override//from ww w . j  a  v  a2s .co m
        public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
            Files.delete(file);
            return FileVisitResult.CONTINUE;
        }

        @Override
        public FileVisitResult postVisitDirectory(Path dir, IOException e) throws IOException {
            if (e == null) {
                Files.delete(dir);
                return FileVisitResult.CONTINUE;
            } else {
                throw e;
            }
        }
    });
}

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

/**
 * Deletes a whole directory (recursively)
 * <p>//w ww  . j a v a  2  s . c  om
 * @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:org.bonitasoft.platform.configuration.util.ConfigurationResourceVisitor.java

@Override
public FileVisitResult visitFile(Path path, BasicFileAttributes basicFileAttributes) throws IOException {
    Objects.requireNonNull(path);
    Objects.requireNonNull(basicFileAttributes);
    final File file = path.toFile();
    if (file.isFile()) {
        try (FileInputStream fileInputStream = new FileInputStream(file)) {
            LOGGER.info("found file " + file.getName());
            bonitaConfigurations/*from w w  w .  j a  va2s .c  o  m*/
                    .add(new BonitaConfiguration(file.getName(), IOUtils.toByteArray(fileInputStream)));
        }
    }
    return FileVisitResult.CONTINUE;
}

From source file:org.apdplat.superword.extract.HyphenExtractor.java

public static Map<String, AtomicInteger> parseDir(String dir) {
    Map<String, AtomicInteger> data = new HashMap<>();
    LOGGER.info("?" + dir);
    try {// ww w  . j a v  a  2  s . c  o  m
        Files.walkFileTree(Paths.get(dir), new SimpleFileVisitor<Path>() {

            @Override
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                Map<String, AtomicInteger> rs = parseFile(file.toFile().getAbsolutePath());
                rs.keySet().forEach(k -> {
                    data.putIfAbsent(k, new AtomicInteger());
                    data.get(k).addAndGet(rs.get(k).get());
                });
                return FileVisitResult.CONTINUE;
            }

        });
    } catch (IOException e) {
        LOGGER.error("?", e);
    }
    return data;
}

From source file:org.bonitasoft.platform.configuration.util.AllConfigurationResourceVisitor.java

@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
    return FileVisitResult.CONTINUE;
}