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:org.sonarsource.scanner.api.Utils.java
public static void deleteQuietly(Path f) { try {/* ww w.j a v a2s . c om*/ Files.walkFileTree(f, new DeleteQuietlyFileVisitor()); } catch (IOException e) { // ignore } }
From source file:org.openehr.adl.TestingArchetypeProvider.java
private Map<String, String> buildArchetypeIdToClasspathMap(final String classpath) throws IOException { final Map<String, String> result = new HashMap<>(); String baseFile = getClass().getClassLoader().getResource(classpath).getFile(); if (baseFile.contains(":") && baseFile.startsWith("/")) baseFile = baseFile.substring(1); final Path basePath = Paths.get(baseFile); Files.walkFileTree(basePath, new SimpleFileVisitor<Path>() { @Override//from ww w. j a v a 2 s. c o m public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { String filename = file.getFileName().toString(); String ext = FilenameUtils.getExtension(filename); if (ext.equalsIgnoreCase("adls") || ext.equalsIgnoreCase("adl")) { String archetypeId = FilenameUtils.getBaseName(filename); String relativePath = basePath.relativize(file).toString(); result.put(archetypeId, Paths.get(classpath).resolve(relativePath).toString()); } return super.visitFile(file, attrs); } }); return result; }
From source file:sh.isaac.pombuilder.FileUtil.java
/** * Recursive delete./*ww w .ja va 2s. c om*/ * * @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:com.preferanser.server.client.DealUploader.java
private List<File> discoverJsonFiles(String jsonDealsPath) throws URISyntaxException, IOException { final List<File> jsonFiles = Lists.newArrayList(); Path path = Paths.get(DealUploader.class.getResource(jsonDealsPath).toURI()); Files.walkFileTree(path, new SimpleFileVisitor<Path>() { @Override/* ww w .java 2 s. c o m*/ public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IOException { File file = path.toFile(); if (attrs.isRegularFile() && file.getName().endsWith(".json")) jsonFiles.add(file); return super.visitFile(path, attrs); } }); return jsonFiles; }
From source file:com.wandoulabs.jodis.TestRoundRobinJedisPool.java
private void deleteDirectory(File directory) throws IOException { if (!directory.exists()) { return;// ww w . j a va2 s. co m } 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.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 ww w . jav a 2 s .c o m*/ 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:fr.ortolang.diffusion.store.binary.BinaryStoreServiceTest.java
@After public void tearDown() { try {/*from www. j av a 2 s. c om*/ 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.cloudbees.clickstack.util.Files2.java
/** * Delete given {@code dir} and its content ({@code rm -rf}). * * @param dir/*from w w w . ja v a 2 s.co 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:com.linecorp.armeria.server.http.file.HttpFileServiceTest.java
@AfterClass public static void destroy() throws Exception { server.stop();//www. ja v a 2 s . co 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:org.bonitasoft.web.designer.controller.export.ZipperTest.java
private void expectSameDirContent(final Path actual, final Path expected) throws IOException { Files.walkFileTree(actual, new SimpleFileVisitor<Path>() { @Override//from w ww . j av a2 s. c o m public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Path expectedFile = expected.resolve(actual.relativize(file)); assertThat(expectedFile.toFile()).exists(); assertThat(expectedFile.toFile()).hasContent(new String(Files.readAllBytes(expectedFile))); return FileVisitResult.CONTINUE; } @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { Path expectedDir = expected.resolve(actual.relativize(dir)); assertThat(expectedDir.toFile()).exists(); return FileVisitResult.CONTINUE; } }); }