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:org.ng200.openolympus.FileAccess.java
public static void deleteDirectoryByWalking(final Path path) throws IOException { if (!Files.exists(path)) { return;/*from w ww . jav a2 s.co m*/ } FileAccess.walkFileTree(path, new SimpleFileVisitor<Path>() { @Override public FileVisitResult postVisitDirectory(final Path dir, final IOException e) throws IOException { if (e == null) { FileAccess.delete(dir); return FileVisitResult.CONTINUE; } else { throw e; } } @Override public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException { FileAccess.delete(file); return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFileFailed(final Path file, final IOException e) throws IOException { FileAccess.delete(file); return FileVisitResult.CONTINUE; } }); Files.deleteIfExists(path); }
From source file:io.mangoo.build.Watcher.java
@SuppressWarnings("all") private void registerAll(final Path path) throws IOException { Files.walkFileTree(path, new SimpleFileVisitor<Path>() { @Override/*w w w . j av a 2 s .com*/ public FileVisitResult preVisitDirectory(Path path, BasicFileAttributes attrs) throws IOException { register(path); return FileVisitResult.CONTINUE; } }); }
From source file:ru.histone.staticrender.StaticRenderTest.java
private void assertFilesEqualsInDirs(final Path expectedDir, final Path actualDir) throws IOException { final Set<String> notFoundInResult = new TreeSet(); final Set<String> unexpectedFilesInResult = new TreeSet(); final Set<String> notIdenticalFiles = new TreeSet(); FileVisitor<Path> filesVisitor1 = new SimpleFileVisitor<Path>() { @Override/*from www . j a v a 2 s . c om*/ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Path relativePath = expectedDir.relativize(file); String expected = new String(Files.readAllBytes(expectedDir.resolve(relativePath)), "UTF-8"); String actual = null; final Path actualFile = actualDir.resolve(relativePath); if (actualFile.toFile().exists()) { actual = new String(Files.readAllBytes(actualFile), "UTF-8"); if (!expected.equals(actual)) { notIdenticalFiles.add(relativePath.toString()); } } else { notFoundInResult.add(relativePath.toString()); } return FileVisitResult.CONTINUE; } }; FileVisitor<Path> filesVisitor2 = new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Path relativePath = actualDir.relativize(file); String expected = new String(Files.readAllBytes(actualDir.resolve(relativePath)), "UTF-8"); String actual = null; final Path actualFile = expectedDir.resolve(relativePath); if (actualFile.toFile().exists()) { actual = new String(Files.readAllBytes(actualFile), "UTF-8"); if (!expected.equals(actual)) { notIdenticalFiles.add(relativePath.toString()); } } else { unexpectedFilesInResult.add(relativePath.toString()); } return FileVisitResult.CONTINUE; } }; Files.walkFileTree(expectedDir, filesVisitor1); Files.walkFileTree(actualDir, filesVisitor2); StringBuilder err = new StringBuilder(); if (notFoundInResult.size() > 0) { err.append("Files not found in result: " + Joiner.on(", ").join(notFoundInResult)).append("\n"); } if (unexpectedFilesInResult.size() > 0) { err.append("Unexpected files found in result: " + Joiner.on(", ").join(unexpectedFilesInResult)) .append("\n"); } if (notIdenticalFiles.size() > 0) { err.append("Files differ in expected and in result: " + Joiner.on(", ").join(notIdenticalFiles)) .append("\n"); } if (err.length() > 0) { fail("Folders diff fail:\n" + err.toString()); } }
From source file:org.hawkular.apm.api.services.ConfigurationLoader.java
/** * This method loads the configuration from the supplied URI. * * @param uri The URI//w ww.jav a 2 s . co m * @param type The type, or null if default (jvm) * @return The configuration */ protected static CollectorConfiguration loadConfig(String uri, String type) { final CollectorConfiguration config = new CollectorConfiguration(); if (type == null) { type = DEFAULT_TYPE; } uri += java.io.File.separator + type; File f = new File(uri); if (!f.isAbsolute()) { if (f.exists()) { uri = f.getAbsolutePath(); } else if (System.getProperties().containsKey("jboss.server.config.dir")) { uri = System.getProperty("jboss.server.config.dir") + java.io.File.separatorChar + uri; } else { try { URL url = Thread.currentThread().getContextClassLoader().getResource(uri); if (url != null) { uri = url.getPath(); } else { log.severe("Failed to get absolute path for uri '" + uri + "'"); } } catch (Exception e) { log.log(Level.SEVERE, "Failed to get absolute path for uri '" + uri + "'", e); uri = null; } } } if (uri != null) { String[] uriParts = uri.split(Matcher.quoteReplacement(File.separator)); int startIndex = 0; // Remove any file prefix if (uriParts[0].equals("file:")) { startIndex++; } try { Path path = getPath(startIndex, uriParts); Files.walkFileTree(path, new FileVisitor<Path>() { @Override public FileVisitResult postVisitDirectory(Path path, IOException exc) throws IOException { return FileVisitResult.CONTINUE; } @Override public FileVisitResult preVisitDirectory(Path path, BasicFileAttributes attrs) throws IOException { return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IOException { if (path.toString().endsWith(".json")) { String json = new String(Files.readAllBytes(path)); CollectorConfiguration childConfig = mapper.readValue(json, CollectorConfiguration.class); if (childConfig != null) { config.merge(childConfig, false); } } return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFileFailed(Path path, IOException exc) throws IOException { return FileVisitResult.CONTINUE; } }); } catch (Throwable e) { log.log(Level.SEVERE, "Failed to load configuration", e); } } return config; }
From source file:org.apache.beam.sdk.extensions.sql.impl.schema.text.BeamTextCSVTableTest.java
@AfterClass public static void teardownClass() throws IOException { Files.walkFileTree(tempFolder, new SimpleFileVisitor<Path>() { @Override//from www . j a v a 2s . com 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.collaborne.jsonschema.generator.pojo.PojoGeneratorSmokeTest.java
@After public void tearDown() throws IOException { // Dump the contents of the file system Path dumpStart = fs.getPath("/"); Files.walkFileTree(dumpStart, new SimpleFileVisitor<Path>() { @Override/*from w ww . j a v a2 s. c o m*/ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { System.out.println("> " + file); System.out.println(new String(Files.readAllBytes(file), StandardCharsets.UTF_8)); // Copy the file if wanted if (DUMP_DIRECTORY != null) { Path dumpTarget = Paths.get(DUMP_DIRECTORY, name.getMethodName()); Path target = dumpTarget.resolve(dumpStart.relativize(file).toString()); Files.createDirectories(target.getParent()); Files.copy(file, target, StandardCopyOption.REPLACE_EXISTING); } return FileVisitResult.CONTINUE; } }); }
From source file:org.roda_project.commons_ip.utils.Utils.java
/** * Deletes a directory/file// w w w. jav a2 s .c o m * * @param path * path to the directory/file that will be deleted. in case of a * directory, if not empty, everything in it will be deleted as well. * * @throws IOException */ public static void deletePath(Path path) throws IOException { if (path == null) { return; } try { Files.delete(path); } catch (DirectoryNotEmptyException e) { LOGGER.debug("Directory is not empty. Going to delete its content as well."); try { 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; } }); } catch (IOException e1) { throw e1; } } catch (IOException e) { throw e; } }
From source file:org.structr.web.maintenance.deploy.FileImportVisitor.java
@Override public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException { if (attrs.isRegularFile()) { createFile(file, file.getFileName().toString()); }//from w w w . j ava 2s . c o m return FileVisitResult.CONTINUE; }
From source file:org.structr.web.maintenance.deploy.TemplateImportVisitor.java
@Override public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException { if (attrs.isRegularFile()) { final String fileName = file.getFileName().toString(); if (fileName.endsWith(".html")) { try { createTemplate(file, fileName); } catch (FrameworkException fex) { logger.warn("Exception while importing shared component {}: {}", new Object[] { name, fex.getMessage() }); }//from w w w . java 2 s .com } } else { logger.warn("Unexpected directory {} found in components/ directory, ignoring", file.getFileName().toString()); } return FileVisitResult.CONTINUE; }
From source file:org.structr.web.maintenance.deploy.PageImportVisitor.java
@Override public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException { try {/* ww w . j a va2s. co m*/ if (attrs.isDirectory()) { createFolder(file); } else if (attrs.isRegularFile()) { final String fileName = file.getFileName().toString(); if (fileName.endsWith(".html")) { try { createPage(file, fileName); } catch (FrameworkException fex) { logger.warn("Exception while importing page {}: {}", new Object[] { fileName, fex.toString() }); } } } } catch (Throwable t) { logger.warn("", t); } return FileVisitResult.CONTINUE; }