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:sh.isaac.pombuilder.FileUtil.java
/** * Recursive delete./*w ww .ja v a2 s . co m*/ * * @param file the file * @throws IOException Signals that an I/O exception has occurred. */ public static void recursiveDelete(File file) throws IOException { if ((file == null) || !file.exists()) { return; } Files.walkFileTree(file.toPath(), 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; } }); file.delete(); }
From source file:fr.ortolang.diffusion.store.binary.BinaryStoreServiceTest.java
@After public void tearDown() { try {/*from w ww . j a va 2 s .c o m*/ Files.walkFileTree(service.getBase(), new FileVisitor<Path>() { @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Files.delete(file); return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException { LOGGER.log(Level.SEVERE, "unable to purge temporary created filesystem", exc); return FileVisitResult.TERMINATE; } @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { Files.delete(dir); return FileVisitResult.CONTINUE; } }); } catch (IOException e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); } }
From source file:com.wandoulabs.jodis.TestRoundRobinJedisPool.java
private void deleteDirectory(File directory) throws IOException { if (!directory.exists()) { return;//www .j av a 2s . c om } Files.walkFileTree(directory.toPath(), 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; } }); }
From source file:org.apdplat.superword.extract.SynonymAntonymExtractor.java
public static Set<SynonymAntonym> parseZip(String zipFile) { Set<SynonymAntonym> data = new HashSet<>(); 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/*from w ww .ja v a 2s. com*/ 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); data.addAll(parseFile(temp.toFile().getAbsolutePath())); return FileVisitResult.CONTINUE; } }); } } catch (Exception e) { LOGGER.error("?", e); } return data; }
From source file:com.linecorp.armeria.server.http.file.HttpFileServiceTest.java
@AfterClass public static void destroy() throws Exception { server.stop();//w w w . j a va2 s .c o m // Delete the temporary files created for testing against the real file system. Files.walkFileTree(tmpDir.toPath(), 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; } }); }
From source file:com.cloudbees.clickstack.util.Files2.java
/** * Delete given {@code dir} and its content ({@code rm -rf}). * * @param dir/*from w w w .ja va2 s.c o m*/ * @throws RuntimeIOException */ public static void deleteDirectory(@Nonnull Path dir) throws RuntimeIOException { try { Files.walkFileTree(dir, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { logger.trace("Delete file: {} ...", file); Files.delete(file); return FileVisitResult.CONTINUE; } @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { if (exc == null) { logger.trace("Delete dir: {} ...", dir); Files.delete(dir); return FileVisitResult.CONTINUE; } else { throw exc; } } }); } catch (IOException e) { throw new RuntimeIOException("Exception deleting '" + dir + "'", e); } }
From source file:org.egov.infra.filestore.service.impl.LocalDiskFileStoreServiceTest.java
@AfterClass public static void afterTest() throws IOException { Files.deleteIfExists(tempFilePath); Path storePath = Paths.get(System.getProperty("user.home") + File.separator + "testfilestore"); try {/*from w w w . j a va 2 s. c om*/ Files.walkFileTree(storePath, 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 { if (exc == null) { Files.delete(dir); return FileVisitResult.CONTINUE; } else { throw exc; } } }); } catch (IOException e) { } }
From source file:org.apache.jmeter.report.dashboard.TemplateVisitor.java
@Override public FileVisitResult preVisitDirectory(Path file, BasicFileAttributes attrs) throws IOException { // Copy directory Path newDir = target.resolve(source.relativize(file)); try {/*from w w w. ja v a 2 s . c o m*/ Files.copy(file, newDir); } catch (FileAlreadyExistsException ex) { // Set directory empty FileUtils.cleanDirectory(newDir.toFile()); } return FileVisitResult.CONTINUE; }
From source file:org.abondar.experimental.eventsearch.SearchData.java
public void indexDocs(final IndexWriter iw, Path path) throws IOException { if (Files.isDirectory(path)) { Files.walkFileTree(path, new SimpleFileVisitor<Path>() { @Override/*from w w w .ja v a 2 s .c om*/ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { try { indexDoc(iw, file, attrs.lastModifiedTime().toMillis()); } catch (IOException ignore) { // don't index files that can't be read. } return FileVisitResult.CONTINUE; } }); } else { indexDoc(iw, path, Files.getLastModifiedTime(path).toMillis()); } }
From source file:org.sonarsource.commandlinezip.ZipUtils7.java
public static void smartReportZip(final Path srcDir, Path zip) throws IOException { try (final OutputStream out = FileUtils.openOutputStream(zip.toFile()); final ZipOutputStream zout = new ZipOutputStream(out)) { Files.walkFileTree(srcDir, new SimpleFileVisitor<Path>() { @Override/*from w ww . j a v a 2s . c o m*/ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { try (InputStream in = new BufferedInputStream(new FileInputStream(file.toFile()))) { String entryName = srcDir.relativize(file).toString(); int level = file.toString().endsWith(".pb") ? ZipOutputStream.STORED : Deflater.DEFAULT_COMPRESSION; zout.setLevel(level); ZipEntry entry = new ZipEntry(entryName); zout.putNextEntry(entry); IOUtils.copy(in, zout); zout.closeEntry(); } return FileVisitResult.CONTINUE; } @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { if (dir.equals(srcDir)) { return FileVisitResult.CONTINUE; } String entryName = srcDir.relativize(dir).toString(); ZipEntry entry = new ZipEntry(entryName); zout.putNextEntry(entry); zout.closeEntry(); return FileVisitResult.CONTINUE; } }); } }