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:org.apdplat.superword.tools.PdfParser.java

public static void parseDirectory(Path dir) {
    try {// w  w  w .  j ava2  s . c  o  m
        long start = System.currentTimeMillis();
        LOGGER.info("?" + dir);
        List<String> fileNames = new ArrayList<>();
        Files.walkFileTree(dir, new SimpleFileVisitor<Path>() {

            @Override
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                String fileName = parseFile(file);
                if (StringUtils.isNotBlank(fileName)) {
                    fileNames.add(fileName);
                }
                return FileVisitResult.CONTINUE;
            }

        });
        Files.write(Paths.get("src/main/resources/it/manifest"), fileNames);
        long cost = System.currentTimeMillis() - start;
        LOGGER.info("?" + cost + "");
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:de.hybris.platform.media.storage.impl.MediaCacheRecreatorTest.java

private void cleanCacheFolder(final String folderName) throws IOException {
    Files.walkFileTree(Paths.get(System.getProperty("java.io.tmpdir"), folderName),
            new SimpleFileVisitor<Path>() {
                @Override//from   ww  w .  j ava 2s. c  o m
                public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs)
                        throws IOException {
                    Files.delete(file);
                    return FileVisitResult.CONTINUE;
                }

                @Override
                public FileVisitResult visitFileFailed(final Path file, final IOException exc)
                        throws IOException {
                    Files.delete(file);
                    return FileVisitResult.CONTINUE;
                }
            });
}

From source file:org.schedulesdirect.grabber.Auditor.java

private void auditScheds() throws IOException, JSONException, ParseException {
    final Map<String, JSONObject> stations = getStationMap();
    final SimpleDateFormat FMT = Config.get().getDateTimeFormat();
    final Path scheds = vfs.getPath("schedules");
    if (Files.isDirectory(scheds)) {
        Files.walkFileTree(scheds, new FileVisitor<Path>() {

            @Override/*from  w w w.  ja  v a 2s .  c om*/
            public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
                return dir.equals(scheds) ? FileVisitResult.CONTINUE : FileVisitResult.SKIP_SUBTREE;
            }

            @Override
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                boolean failed = false;
                String id = getStationIdFromFileName(file.getFileName().toString());
                JSONObject station = stations.get(id);
                StringBuilder msg = new StringBuilder(String.format("Inspecting %s (%s)... ",
                        station != null ? station.getString("callsign") : String.format("[UNKNOWN: %s]", id),
                        id));
                String input;
                try (InputStream ins = Files.newInputStream(file)) {
                    input = IOUtils.toString(ins, ZipEpgClient.ZIP_CHARSET.toString());
                }
                ObjectMapper mapper = Config.get().getObjectMapper();
                JSONArray jarr = mapper.readValue(
                        mapper.readValue(input, JSONObject.class).getJSONArray("programs").toString(),
                        JSONArray.class);
                for (int i = 1; i < jarr.length(); ++i) {
                    long start, prevStart;
                    JSONObject prev;
                    try {
                        start = FMT.parse(jarr.getJSONObject(i).getString("airDateTime")).getTime();
                        prev = jarr.getJSONObject(i - 1);
                        prevStart = FMT.parse(prev.getString("airDateTime")).getTime()
                                + 1000L * prev.getLong("duration");
                    } catch (ParseException e) {
                        throw new RuntimeException(e);
                    }
                    if (prevStart != start) {
                        msg.append(String.format("FAILED! [%s]", prev.getString("airDateTime")));
                        LOG.error(msg);
                        failed = true;
                        Auditor.this.failed = true;
                        break;
                    }
                }
                if (!failed) {
                    msg.append("PASSED!");
                    LOG.info(msg);
                }
                return FileVisitResult.CONTINUE;
            }

            @Override
            public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
                LOG.error(String.format("Unable to process schedule file '%s'", file), exc);
                Auditor.this.failed = true;
                return FileVisitResult.CONTINUE;
            }

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

        });
    }
}

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

@Override
public FileVisitResult visitFile(Path path, BasicFileAttributes basicFileAttributes) throws IOException {
    Objects.requireNonNull(path);
    Objects.requireNonNull(basicFileAttributes);
    final File file = path.toFile();
    if (isConfigurationFile(path)) {
        final Long tenantId = getTenantId(path.getParent());
        final String configurationType = getFolderName(path.getParent());
        try (FileInputStream fileInputStream = new FileInputStream(file)) {
            LOGGER.debug(buildMessage(file, tenantId, configurationType));
            fullBonitaConfigurations.add(new FullBonitaConfiguration(file.getName(),
                    IOUtils.toByteArray(fileInputStream), configurationType, tenantId));
        }/*from   w  w w .j  av  a2s  . c o m*/
    }
    return FileVisitResult.CONTINUE;
}

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

public static Map<String, AtomicInteger> parseZip(String zipFile) {
    Map<String, AtomicInteger> data = new HashMap<>();
    LOGGER.info("?ZIP" + zipFile);
    try (FileSystem fs = FileSystems.newFileSystem(Paths.get(zipFile), WordClassifier.class.getClassLoader())) {
        for (Path path : fs.getRootDirectories()) {
            LOGGER.info("?" + path);
            Files.walkFileTree(path, new SimpleFileVisitor<Path>() {

                @Override/*w w w  .ja  va  2 s  .c  om*/
                public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                    LOGGER.info("?" + file);
                    // ?
                    Path temp = Paths.get("target/origin-html-temp.txt");
                    Files.copy(file, temp, StandardCopyOption.REPLACE_EXISTING);
                    Map<String, AtomicInteger> rs = parseFile(temp.toFile().getAbsolutePath());
                    rs.keySet().forEach(k -> {
                        data.putIfAbsent(k, new AtomicInteger());
                        data.get(k).addAndGet(rs.get(k).get());
                    });
                    return FileVisitResult.CONTINUE;
                }

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

From source file:org.neo4j.graphdb.LuceneLabelScanStoreIT.java

private void corruptIndex(NeoStoreDataSource dataSource) throws IOException {
    File labelScanStoreDirectory = getLabelScanStoreDirectory(dataSource);
    Files.walkFileTree(labelScanStoreDirectory.toPath(), new SimpleFileVisitor<Path>() {
        @Override/*from  w  w  w.  j  av a2 s.  c o m*/
        public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
            Files.write(file, ArrayUtils.add(Files.readAllBytes(file), (byte) 7));
            return FileVisitResult.CONTINUE;
        }
    });
}

From source file:de.thomasbolz.renamer.Renamer.java

/**
 * Step 1 of the renaming process://from   www.  ja va2s. com
 * Analysis steps in the renaming process. Walks the whole file tree of the source directory and creates a CopyTask
 * for each file or directory that is found and does not match the exclusion list.
 * @return a list of all CopyTasks
 */
public Map<Path, List<CopyTask>> prepareCopyTasks() {

    try {
        Files.walkFileTree(source, EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE,
                new SimpleFileVisitor<Path>() {

                    /**
                     * If we find a directory create/copy it and add a counter
                     *
                     * @param dir
                     * @param attrs
                     * @return
                     * @throws java.io.IOException
                     */
                    @Override
                    public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs)
                            throws IOException {
                        Path targetdir = target.resolve(source.relativize(dir));
                        copyTasks.put(dir, new ArrayList<CopyTask>());
                        return FileVisitResult.CONTINUE;
                    }

                    @Override
                    public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                        if (!file.getFileName().toString().toLowerCase().matches(EXLUSION_REGEX)) {
                            copyTasks.get(file.getParent()).add(new CopyTask(file, null));
                        } else {
                            excludedFiles.add(file);
                        }
                        return FileVisitResult.CONTINUE;
                    }
                });
    } catch (IOException e) {
        e.printStackTrace();
    }
    sortCopyTasks();
    //        generateTargetFilenames();
    return copyTasks;
}

From source file:org.phenotips.variantstore.input.exomiser6.tsv.Exomiser6TSVManager.java

@Override
public List<String> getAllIndividuals() {
    final List<String> list = new ArrayList<>();

    try {/*from w w w.ja  v  a 2s  . c  o m*/
        Files.walkFileTree(this.path, new SimpleFileVisitor<Path>() {
            @Override
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                if (attrs.isDirectory()) {
                    return FileVisitResult.CONTINUE;
                }
                String filename = file.getFileName().toString();
                String id = StringUtils.removeEnd(filename, suffix);
                list.add(id);
                return FileVisitResult.CONTINUE;
            }
        });
    } catch (IOException e) {
        logger.error("Error getting all individuals", e);
    }

    return list;
}

From source file:com.yahoo.bard.webservice.util.Utils.java

/**
 * Delete files or directories in the specified path.
 *
 * @param path  The pathname//from w w w .  j av a  2 s .  c  o  m
 */
public static void deleteFiles(String path) {
    Path directory = Paths.get(path);

    try {
        Files.walkFileTree(directory, new SimpleFileVisitor<Path>() {
            @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 {
                Files.delete(dir);
                return FileVisitResult.CONTINUE;
            }

        });
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.application.backupsync.PathName.java

public List<PathName> walk() throws IOException {
    final List<PathName> result;

    result = new ArrayList<>();

    if (Files.isReadable(this.path)) {
        Files.walkFileTree(this.path, new SimpleFileVisitor<Path>() {

            @Override//from   www  . j a va 2 s  .c  o m
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                result.add(new PathName(file));
                return FileVisitResult.CONTINUE;
            }

            @Override
            public FileVisitResult postVisitDirectory(Path dir, IOException ex) {
                result.add(new PathName(dir));
                return FileVisitResult.CONTINUE;
            }
        });
    } else {
        throw new IllegalArgumentException("Directory cannot be read: " + this.path.toString());
    }
    return result;
}