List of usage examples for java.nio.file FileVisitResult CONTINUE
FileVisitResult CONTINUE
To view the source code for java.nio.file FileVisitResult CONTINUE.
Click Source Link
From source file:com.facebook.buck.io.ProjectFilesystemTest.java
@Test public void testWalkFileTreeWhenProjectRootIsNotWorkingDir() throws IOException { tmp.newFolder("dir"); tmp.newFile("dir/file.txt"); tmp.newFolder("dir/dir2"); tmp.newFile("dir/dir2/file2.txt"); final ImmutableList.Builder<String> fileNames = ImmutableList.builder(); filesystem.walkRelativeFileTree(Paths.get("dir"), new SimpleFileVisitor<Path>() { @Override/* w w w . ja v a 2 s . c o m*/ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { fileNames.add(file.getFileName().toString()); return FileVisitResult.CONTINUE; } }); assertThat(fileNames.build(), containsInAnyOrder("file.txt", "file2.txt")); }
From source file:dk.dma.ais.downloader.QueryService.java
/** * Deletes all the file of the client folder *///from w ww.ja va 2 s . c om @RequestMapping(value = "/delete-all/{clientId}", method = RequestMethod.GET) @ResponseBody public String deleteFiles(@PathVariable("clientId") String clientId, HttpServletResponse response) throws IOException { int deletedFiles = 0; Path path = repoRoot.resolve(clientId); if (Files.notExists(path) || !Files.isDirectory(path)) { log.log(Level.WARNING, "Failed deleting files in " + path); response.setStatus(404); return "Failed deleting files in " + clientId; } try { Files.walkFileTree(path, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { log.info("Deleting repo file :" + file); Files.delete(file); return FileVisitResult.CONTINUE; } }); } catch (IOException e) { log.log(Level.SEVERE, "Failed cleaning up dir: " + path); return "Failed deleting files in " + clientId; } return "Deleted files in dir " + clientId; }
From source file:com.datafibers.kafka.connect.FileGenericSourceTask.java
/** * Looks for files that meet the glob criteria. If any found they will be added to the list of * files to be processed/*from w ww . j a v a 2 s. co m*/ */ private void findMatch() { final PathMatcher globMatcher = FileSystems.getDefault().getPathMatcher("glob:".concat(glob)); try { Files.walkFileTree(Paths.get(location), new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path path, BasicFileAttributes attributes) throws IOException { if (globMatcher.matches(path)) { if (!processedPaths.contains(path)) { inProgressPaths.add(path); } } return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFileFailed(Path file, IOException e) throws IOException { return FileVisitResult.CONTINUE; } }); } catch (IOException e) { e.printStackTrace(); } }
From source file:org.apache.jena.atlas.io.IO.java
/** Delete everything from a {@code Path} start point, including the path itself. * This function works on files or directories. * This function does not follow symbolic links. *///from w w w . j av a2 s . c om public static void deleteAll(Path start) { // Walks down the tree and delete directories on the way backup. try { Files.walkFileTree(start, 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 e) throws IOException { if (e == null) { Files.delete(dir); return FileVisitResult.CONTINUE; } else { throw e; } } }); } catch (IOException ex) { IO.exception(ex); return; } }
From source file:facs.utils.Billing.java
/** * Helper method. copies files and directories from source to target source and target can be * created via the command: FileSystems.getDefault().getPath(String path, ... String more) or * Paths.get(String path, ... String more) Note: overrides existing folders * //from w w w . jav a2s . c o m * @param source * @param target * @return true if copying was successful */ public boolean copy(final Path source, final Path target) { try { Files.walkFileTree(source, EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, new SimpleFileVisitor<Path>() { @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { Path targetdir = target.resolve(source.relativize(dir)); try { Files.copy(dir, targetdir, java.nio.file.StandardCopyOption.REPLACE_EXISTING); } catch (FileAlreadyExistsException e) { if (!Files.isDirectory(targetdir)) { throw e; } } return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Files.copy(file, target.resolve(source.relativize(file))); return FileVisitResult.CONTINUE; } }); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); return false; } return true; }
From source file:org.eclipse.winery.repository.importing.CSARImporter.java
/** * Import an extracted CSAR from a directory * //from w w w.j ava 2 s. c o m * @param path the root path of an extracted CSAR file * @param overwrite if true: contents of the repo are overwritten * @param asyncWPDParsing true if WPD should be parsed asynchronously to speed up the import. * Required, because JUnit terminates the used ExecutorService * @throws InvalidCSARException * @throws IOException */ void importFromDir(final Path path, final List<String> errors, final boolean overwrite, final boolean asyncWPDParsing) throws IOException { Path toscaMetaPath = path.resolve("xml/TOSCA-Metadata/TOSCA.meta"); if (!Files.exists(toscaMetaPath)) { toscaMetaPath = path.resolve("TOSCA-Metadata/TOSCA.meta"); } if (!Files.exists(toscaMetaPath)) { errors.add("TOSCA.meta does not exist"); return; } final TOSCAMetaFileParser tmfp = new TOSCAMetaFileParser(); final TOSCAMetaFile tmf = tmfp.parse(toscaMetaPath); // we do NOT do any sanity checks, of TOSAC.meta // and just start parsing if (tmf.getEntryDefinitions() != null) { // we obey the entry definitions and "just" import that // imported definitions are added recursively Path defsPath = path.resolve(tmf.getEntryDefinitions()); this.importDefinitions(tmf, defsPath, errors, overwrite, asyncWPDParsing); this.importSelfServiceMetaData(tmf, path, defsPath, errors); } else { // no explicit entry definitions found // we import all available definitions // The specification says (cos01, Section 16.1, line 2935) that all definitions are contained // in the "Definitions" directory // The alternative is to go through all entries in the TOSCA Meta File, but there is no // guarantee that this list is complete Path definitionsDir = path.resolve("Definitions"); if (!Files.exists(definitionsDir)) { errors.add("No entry definitions defined and Definitions directory does not exist."); return; } final List<IOException> exceptions = new ArrayList<IOException>(); Files.walkFileTree(definitionsDir, new SimpleFileVisitor<Path>() { @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) { if (dir.endsWith("Definitions")) { return FileVisitResult.CONTINUE; } else { return FileVisitResult.SKIP_SUBTREE; } } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { try { CSARImporter.this.importDefinitions(tmf, file, errors, overwrite, asyncWPDParsing); } catch (IOException e) { exceptions.add(e); return FileVisitResult.TERMINATE; } return FileVisitResult.CONTINUE; } }); if (!exceptions.isEmpty()) { // something went wrong during parsing // we rethrow the exception throw exceptions.get(0); } } this.importNamespacePrefixes(path); }
From source file:com.facebook.buck.util.ProjectFilesystemTest.java
@Test public void testWalkFileTreeWhenProjectRootIsWorkingDir() throws IOException { ProjectFilesystem projectFilesystem = new ProjectFilesystem(Paths.get(".")); final ImmutableList.Builder<String> fileNames = ImmutableList.builder(); Path pathRelativeToProjectRoot = Paths.get("test/com/facebook/buck/util/testdata"); projectFilesystem.walkRelativeFileTree(pathRelativeToProjectRoot, new SimpleFileVisitor<Path>() { @Override/*from www. j a v a 2s .c om*/ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { fileNames.add(file.getFileName().toString()); return FileVisitResult.CONTINUE; } }); assertThat(fileNames.build(), containsInAnyOrder("file", "a_file", "b_file", "b_c_file", "b_d_file")); }
From source file:org.vpac.ndg.storage.util.TimeSliceUtil.java
public void cleanup(String timesliceId) { TimeSlice ts = timeSliceDao.retrieve(timesliceId); Path tsPath = getFileLocation(ts); try {//w ww .j ava 2s . co m Files.walkFileTree(tsPath, new SimpleFileVisitor<Path>() { /** * Import netcdf dataset */ @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { String fileName = file.getFileName().toString(); if (!fileName.endsWith("_old" + GdalFormat.NC.getExtension())) { // IGNORE NON-BACKUP TILE return FileVisitResult.CONTINUE; } Path backupTilePath = file.toAbsolutePath(); try { FileUtils.deleteIfExists(backupTilePath); log.debug("CLEAN UP {}", backupTilePath); } catch (Exception e) { log.error("{}", e); } return FileVisitResult.CONTINUE; } @Override public FileVisitResult postVisitDirectory(Path dir, IOException e) throws IOException { return FileVisitResult.CONTINUE; } }); } catch (IOException e) { log.error("Error restoring {} caused by {}", tsPath, e); } }
From source file:com.facebook.buck.io.ProjectFilesystemTest.java
@Test public void testWalkFileTreeWhenProjectRootIsWorkingDir() throws IOException { ProjectFilesystem projectFilesystem = new ProjectFilesystem(Paths.get(".").toAbsolutePath()); final ImmutableList.Builder<String> fileNames = ImmutableList.builder(); Path pathRelativeToProjectRoot = Paths .get("test/com/facebook/buck/io/testdata/directory_traversal_ignore_paths"); projectFilesystem.walkRelativeFileTree(pathRelativeToProjectRoot, new SimpleFileVisitor<Path>() { @Override/* www. j av a 2s . c o m*/ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { fileNames.add(file.getFileName().toString()); return FileVisitResult.CONTINUE; } }); assertThat(fileNames.build(), containsInAnyOrder("file", "a_file", "b_file", "b_c_file", "b_d_file")); }
From source file:org.hawkular.inventory.impl.tinkerpop.test.BasicTest.java
private static void deleteGraph() throws Exception { Path path = Paths.get("./", "__tinker.graph"); if (!path.toFile().exists()) { return;//from w w w.j av a 2 s . co m } Files.walkFileTree(path, 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; } }); }