List of usage examples for java.nio.file Files walkFileTree
public static Path walkFileTree(Path start, FileVisitor<? super Path> visitor) throws IOException
From source file:de.elomagic.carafile.client.CaraCloud.java
private List<Path> getLocalChangeList(final Path basePath, final long lastScanMillis) throws IOException { if (Files.notExists(basePath)) { return Collections.EMPTY_LIST; }//from w w w.j a v a 2s .co m final List<Path> changedPathList = new ArrayList(); Files.walkFileTree(basePath, new SimpleFileVisitor<Path>() { @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { if (attrs.lastModifiedTime().toMillis() > lastScanMillis) { changedPathList.add(dir); } return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (attrs.lastModifiedTime().toMillis() > lastScanMillis) { changedPathList.add(file); } return FileVisitResult.CONTINUE; } }); return changedPathList; }
From source file:net.gcolin.simplerepo.search.SearchController.java
public void rebuild() throws IOException { if (running) { return;// ww w .ja va2s . com } running = true; configManager.setCurrentAction(REBUILD + "initialize"); nb = 0; try { final QueryRunner run = new QueryRunner(); try { Connection connection = null; try { connection = datasource.getConnection(); connection.setAutoCommit(false); run.update(connection, "delete from artifacttype"); run.update(connection, "delete from artifactversion"); run.update(connection, "delete from artifact"); run.update(connection, "update artifactindex set artifact=1,version=1"); connection.commit(); } catch (SQLException ex) { connection.rollback(); throw ex; } finally { DbUtils.close(connection); } } catch (SQLException ex) { logger.log(Level.SEVERE, null, ex); throw new IOException(ex); } for (final Repository repository : configManager.getConfiguration().getRepositories()) { File repo = new File(configManager.getRoot(), repository.getName()); if (repo.exists()) { Files.walkFileTree(repo.toPath(), new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { nb++; if (nb % 20 == 0) { configManager.setCurrentAction(REBUILD + " " + nb + " files"); } if (file.toString().endsWith(".pom")) { Model model = readPom(file.toFile()); add(repository, file.toFile(), model); } return FileVisitResult.CONTINUE; } }); } } } finally { running = false; configManager.setCurrentAction(null); } }
From source file:science.atlarge.graphalytics.powergraph.PowergraphPlatform.java
@Override public BenchmarkMetrics finalize(RunSpecification runSpecification) { stopPlatformLogging();//w w w . j a va 2 s.c om BenchmarkRunSetup benchmarkRunSetup = runSpecification.getBenchmarkRunSetup(); BenchmarkRun benchmarkRun = runSpecification.getBenchmarkRun(); Path platformLogPath = benchmarkRunSetup.getLogDir().resolve("platform"); final List<Double> superstepTimes = new ArrayList<>(); try { Files.walkFileTree(platformLogPath, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { String logs = FileUtil.readFile(file); for (String line : logs.split("\n")) { if (line.contains("- run algorithm:")) { Pattern regex = Pattern.compile(".* - run algorithm: ([+-]?([0-9]*[.])?[0-9]+) sec.*"); Matcher matcher = regex.matcher(line); matcher.find(); superstepTimes.add(Double.parseDouble(matcher.group(1))); } } return FileVisitResult.CONTINUE; } }); } catch (IOException e) { e.printStackTrace(); } if (superstepTimes.size() != 0) { Double procTime = 0.0; for (Double superstepTime : superstepTimes) { procTime += superstepTime; } BenchmarkMetrics metrics = new BenchmarkMetrics(); BigDecimal procTimeS = (new BigDecimal(procTime)).setScale(3, RoundingMode.CEILING); metrics.setProcessingTime(new BenchmarkMetric(procTimeS, "s")); return metrics; } else { LOG.error("Failed to find any metrics regarding superstep runtime."); return new BenchmarkMetrics(); } }
From source file:com.sastix.cms.server.services.content.HashedDirectoryServiceTest.java
private void deleteRecursive(Path path) throws IOException { Files.walkFileTree(path, new SimpleFileVisitor<Path>() { @Override//from www . j a va2 s. c o m 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:com.yahoo.parsec.gradle.utils.FileUtils.java
/** * Find files in path.//from w ww . j a v a 2s . c o m * * @param path find path * @param pattern find patttern * @return a set of path * @throws IOException IOException */ public Set<Path> findFiles(String path, String pattern) throws IOException { try { Set<Path> paths = new HashSet<>(); PathMatcher pathMatcher = FileSystems.getDefault().getPathMatcher(pattern); Files.walkFileTree(Paths.get(path), new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path filePath, BasicFileAttributes attrs) { if (pathMatcher.matches(filePath.getFileName())) { paths.add(filePath); } return FileVisitResult.CONTINUE; } }); return paths; } catch (IOException e) { throw e; } }
From source file:ee.ria.xroad.common.conf.globalconf.ConfigurationDirectory.java
/** * Applies the given function to all files belonging to * the configuration directory./*from www .j ava2 s. com*/ * @param consumer the function instance that should be applied to * @throws Exception if an error occurs */ protected synchronized void eachFile(final Consumer<Path> consumer) throws Exception { Files.walkFileTree(path, new Walker(consumer)); }
From source file:org.talend.dataprep.cache.file.FileSystemContentCache.java
@Override @Timed//w w w. j av a 2s . c o m public void evictMatch(ContentCacheKey key) { final Path path = computeEntryPath(key, null); final Path parent = path.getParent(); // defensive programming if (!parent.toFile().exists()) { return; } try { final Predicate<String> matchKey = key.getMatcher(); final BiConsumer<Path, String> evictKey = getEvictionConsumer(matchKey); final boolean skipPermanentEntries = false; Files.walkFileTree(Paths.get(location), new FileSystemVisitor(evictKey, skipPermanentEntries)); } catch (IOException e) { LOGGER.error("Unable to evict.", e); } LOGGER.debug("[{}] Evict Match.", key); }
From source file:lucene.IndexFiles.java
/** 135 * Indexes the given file using the given writer, or if a directory is given, 136 * recurses over files and directories found under the given directory. 137 * /*www . j a va2 s.com*/ 138 * NOTE: This method indexes one document per input file. This is slow. For good 139 * throughput, put multiple documents into your input file(s). An example of this is 140 * in the benchmark module, which can create "line doc" files, one document per line, 141 * using the 142 * <a href="../../../../../contrib-benchmark/org/apache/lucene/benchmark/byTask/tasks/WriteLineDocTask.html" 143 * >WriteLineDocTask</a>. 144 * 145 * @param writer Writer to the index where the given file/dir info will be stored 146 * @param path The file to index, or the directory to recurse into to find files to index 147 * @throws IOException If there is a low-level I/O error 148 */ static void indexDocs(final IndexWriter writer, Path path) throws IOException { System.out.println("Test 2.1"); if (Files.isDirectory(path)) { System.out.println("Test 2.2"); Files.walkFileTree(path, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { try { System.out.println("Test 2.3"); System.out.println(file.toString()); indexDoc(writer, file, attrs.lastModifiedTime().toMillis()); System.out.println("Test 2.4"); } catch (IOException ignore) { // don't index files that can't be read. } return FileVisitResult.CONTINUE; } }); } else { indexDoc(writer, path, Files.getLastModifiedTime(path).toMillis()); } }
From source file:org.openeos.tools.maven.plugins.GenerateEntitiesMojo.java
private Set<File> checkForLocalFiles(File file) throws IOException, URISyntaxException { final Set<File> result = new TreeSet<File>(); final PathMatcher matcher = FileSystems.getDefault() .getPathMatcher("glob:" + file.getAbsolutePath() + "/" + searchpath); SimpleFileVisitor<Path> fileVisitor = new SimpleFileVisitor<Path>() { @Override/*from w w w . j a va 2 s . c o m*/ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (matcher.matches(file)) { result.add(file.toFile()); } return FileVisitResult.CONTINUE; } }; Files.walkFileTree(file.toPath(), fileVisitor); return result; }
From source file:com.liferay.sync.engine.SyncSystemTest.java
protected void addFolder(Path testFilePath, JsonNode stepJsonNode) throws Exception { SyncSite syncSite = getSyncSite(stepJsonNode); String dependency = getString(stepJsonNode, "dependency"); final Path dependencyFilePath = getDependencyFilePath(testFilePath, dependency); FileSystem fileSystem = FileSystems.getDefault(); final Path targetFilePath = Paths.get(FileUtil.getFilePathName(syncSite.getFilePathName(), dependency.replace("common" + fileSystem.getSeparator(), ""))); Files.walkFileTree(dependencyFilePath, new SimpleFileVisitor<Path>() { @Override/*from w w w. j a v a 2 s . c o m*/ public FileVisitResult preVisitDirectory(Path filePath, BasicFileAttributes basicFileAttributes) throws IOException { Path relativeFilePath = dependencyFilePath.relativize(filePath); Files.createDirectories(targetFilePath.resolve(relativeFilePath)); return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFile(Path filePath, BasicFileAttributes basicFileAttributes) throws IOException { Path relativeFilePath = dependencyFilePath.relativize(filePath); Files.copy(filePath, targetFilePath.resolve(relativeFilePath)); return FileVisitResult.CONTINUE; } }); }