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.liferay.sync.engine.SyncSystemTest.java
protected static void cleanUp(long delay) throws Exception { for (long syncAccountId : _syncAccountIds.values()) { SyncAccount syncAccount = SyncAccountService.fetchSyncAccount(syncAccountId); if (syncAccount == null) { return; }//from w w w. ja va 2 s .co m Files.walkFileTree(Paths.get(syncAccount.getFilePathName()), new SimpleFileVisitor<Path>() { @Override public FileVisitResult postVisitDirectory(Path filePath, IOException ioe) throws IOException { Files.deleteIfExists(filePath); return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFile(Path filePath, BasicFileAttributes basicFileAttributes) throws IOException { Files.deleteIfExists(filePath); return FileVisitResult.CONTINUE; } }); } pause(delay); SyncEngine.stop(); Files.walkFileTree(Paths.get(_rootFilePathName), new SimpleFileVisitor<Path>() { @Override public FileVisitResult postVisitDirectory(Path filePath, IOException ioe) throws IOException { Files.delete(filePath); return FileVisitResult.CONTINUE; } }); for (long syncAccountId : _syncAccountIds.values()) { SyncAccount syncAccount = SyncAccountService.fetchSyncAccount(syncAccountId); SyncSystemTestUtil.deleteUser(syncAccount.getUserId(), _syncAccount.getSyncAccountId()); SyncAccountService.deleteSyncAccount(syncAccountId); } SyncAccountService.deleteSyncAccount(_syncAccount.getSyncAccountId()); }
From source file:software.coolstuff.springframework.owncloud.service.impl.local.OwncloudLocalResourceServiceCopyWebdavDirectoryTestExecutionListener.java
private void cleanDirectory(Path directory) { if (!Files.isDirectory(directory)) { return;/* w ww.j ava 2 s .c o m*/ } try { log.debug("Remove all Contents of Directory {}", directory.toAbsolutePath().toString()); Files.walkFileTree(directory, 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 (!Files.isSameFile(dir, directory)) { Files.delete(dir); } return FileVisitResult.CONTINUE; } }); Files.delete(directory); } catch (IOException e) { throw new RuntimeException( String.format("IOException while cleaning Directory %s", directory.toAbsolutePath().toString()), e); } }
From source file:services.ImportExportService.java
public static void importDirectoryRecursive(final Project project, Path root) throws IOException { Files.walkFileTree(root, new SimpleFileVisitor<Path>() { @Override//from w w w . j a v a2s.com public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IOException { if (PathService.isImage(path)) { DatabaseImage image = DatabaseImage.forPath(path); if (!image.imported && hasFileToImport(image)) importData(project, image); } return FileVisitResult.CONTINUE; } }); }
From source file:org.sonarsource.commandlinezip.ZipUtils7.java
public static void fastZip(final Path srcDir, Path zip) throws IOException { try (final OutputStream out = FileUtils.openOutputStream(zip.toFile()); final ZipOutputStream zout = new ZipOutputStream(out)) { zout.setMethod(ZipOutputStream.STORED); Files.walkFileTree(srcDir, new SimpleFileVisitor<Path>() { @Override// w w w.ja v a 2 s.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(); 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; } }); } }
From source file:com.dotcms.content.elasticsearch.business.ESIndexHelper.java
/** * Finds file within the directory named "snapshot-" * @param snapshotDirectory//w w w .j a va 2 s. co m * @return * @throws IOException */ public String findSnapshotName(File snapshotDirectory) throws IOException { String name = null; if (snapshotDirectory.isDirectory()) { class SnapshotVisitor extends SimpleFileVisitor<Path> { private String fileName; public String getFileName() { return fileName; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (file.getFileName().toString().startsWith(SNAPSHOT_PREFIX)) { fileName = file.getFileName().toString(); return FileVisitResult.TERMINATE; } return FileVisitResult.CONTINUE; } @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { return FileVisitResult.CONTINUE; } } Path directory = Paths.get(snapshotDirectory.getAbsolutePath()); SnapshotVisitor snapshotVisitor = new SnapshotVisitor(); Files.walkFileTree(directory, snapshotVisitor); String fullName = snapshotVisitor.getFileName(); if (fullName != null) { name = fullName.replaceFirst(SNAPSHOT_PREFIX, ""); } } return name; }
From source file:com.garyclayburg.filesystem.WatchDir.java
/** * Register the given directory, and all its sub-directories, with the * WatchService.//from ww w . j a va2 s. co m */ private void registerAll(final Path start) throws IOException { // register directory and sub-directories Files.walkFileTree(start, new SimpleFileVisitor<Path>() { @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { register(dir); return FileVisitResult.CONTINUE; } }); }
From source file:ru.histone.staticrender.StaticRender.java
public void renderSite(final Path srcDir, final Path dstDir) { log.info("Running StaticRender for srcDir={}, dstDir={}", srcDir.toString(), dstDir.toString()); Path contentDir = srcDir.resolve("content/"); final Path layoutDir = srcDir.resolve("layouts/"); FileVisitor<Path> layoutVisitor = new SimpleFileVisitor<Path>() { @Override/*from w w w . j av a2 s .c o m*/ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (file.toString().endsWith("." + TEMPLATE_FILE_EXTENSION)) { ArrayNode ast = null; try { ast = histone.parseTemplateToAST(new FileReader(file.toFile())); } catch (HistoneException e) { throw new RuntimeException("Error parsing histone template:" + e.getMessage(), e); } final String fileName = file.getFileName().toString(); String layoutId = fileName.substring(0, fileName.length() - TEMPLATE_FILE_EXTENSION.length() - 1); layouts.put(layoutId, ast); if (log.isDebugEnabled()) { log.debug("Layout found id='{}', file={}", layoutId, file); } else { log.info("Layout found id='{}'", layoutId); } } else { final Path relativeFileName = srcDir.resolve("layouts").relativize(Paths.get(file.toUri())); final Path resolvedFile = dstDir.resolve(relativeFileName); if (!resolvedFile.getParent().toFile().exists()) { Files.createDirectories(resolvedFile.getParent()); } Files.copy(Paths.get(file.toUri()), resolvedFile, StandardCopyOption.REPLACE_EXISTING, LinkOption.NOFOLLOW_LINKS); } return FileVisitResult.CONTINUE; } }; FileVisitor<Path> contentVisitor = new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Scanner scanner = new Scanner(file, "UTF-8"); scanner.useDelimiter("-----"); String meta = null; StringBuilder content = new StringBuilder(); if (!scanner.hasNext()) { throw new RuntimeException("Wrong format #1:" + file.toString()); } if (scanner.hasNext()) { meta = scanner.next(); } if (scanner.hasNext()) { content.append(scanner.next()); scanner.useDelimiter("\n"); } while (scanner.hasNext()) { final String next = scanner.next(); content.append(next); if (scanner.hasNext()) { content.append("\n"); } } Map<String, String> metaYaml = (Map<String, String>) yaml.load(meta); String layoutId = metaYaml.get("layout"); if (!layouts.containsKey(layoutId)) { throw new RuntimeException(MessageFormat.format("No layout with id='{0}' found", layoutId)); } final Path relativeFileName = srcDir.resolve("content").relativize(Paths.get(file.toUri())); final Path resolvedFile = dstDir.resolve(relativeFileName); if (!resolvedFile.getParent().toFile().exists()) { Files.createDirectories(resolvedFile.getParent()); } Writer output = new FileWriter(resolvedFile.toFile()); ObjectNode context = jackson.createObjectNode(); ObjectNode metaNode = jackson.createObjectNode(); context.put("content", content.toString()); context.put("meta", metaNode); for (String key : metaYaml.keySet()) { if (!key.equalsIgnoreCase("content")) { metaNode.put(key, metaYaml.get(key)); } } try { histone.evaluateAST(layoutDir.toUri().toString(), layouts.get(layoutId), context, output); output.flush(); } catch (HistoneException e) { throw new RuntimeException("Error evaluating content: " + e.getMessage(), e); } finally { output.close(); } return FileVisitResult.CONTINUE; } }; try { Files.walkFileTree(layoutDir, layoutVisitor); Files.walkFileTree(contentDir, contentVisitor); } catch (Exception e) { throw new RuntimeException("Error during site render", e); } }
From source file:org.apdplat.superword.tools.WordClassifier.java
public static void parseZip(String zipFile) { 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 ww w. jav a 2s. c om*/ 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); parseFile(temp.toFile().getAbsolutePath()); return FileVisitResult.CONTINUE; } }); } } catch (Exception e) { LOGGER.error("?", e); } }
From source file:org.zaproxy.VerifyScripts.java
private static void readFiles() throws Exception { Optional<String> path = Arrays.stream(System.getProperty("java.class.path").split(File.pathSeparator)) .filter(e -> e.endsWith("/scripts")).findFirst(); assertThat(path).as("The scripts directory was not found on the classpath.").isPresent(); List<Path> unexpectedFiles = new ArrayList<>(); MutableInt depth = new MutableInt(); files = new ArrayList<>(); Files.walkFileTree(Paths.get(path.get()), new SimpleFileVisitor<Path>() { @Override//from ww w . j a v a 2 s. c o m public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { depth.increment(); return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { if (depth.intValue() != SCRIPT_TYPE_DIR_DEPTH) { unexpectedFiles.add(file); return FileVisitResult.CONTINUE; } if (!isExpectedNonScriptFile(file)) { files.add(file); } return FileVisitResult.CONTINUE; } @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { depth.decrement(); return FileVisitResult.CONTINUE; } }); assertThat(unexpectedFiles).as("Files found not in a script type directory.").isEmpty(); Collections.sort(files); }
From source file:io.liveoak.testtools.AbstractTestCase.java
@AfterClass public static void tearDownMongo() throws IOException { if (mongoLauncher != null) { mongoLauncher.stopMongo();//from www. jav a 2 s .c o m // wait for it to stop long start = System.currentTimeMillis(); while (mongoLauncher.serverRunning(mongoHost, mongoPort, (e) -> { if (System.currentTimeMillis() - start > 120000) throw new RuntimeException(e); })) { if (System.currentTimeMillis() - start > 120000) { throw new RuntimeException("mongod process still seems to be running (2m timeout)"); } try { Thread.sleep(300); } catch (InterruptedException e) { throw new RuntimeException("Interrupted!"); } } // now delete the data dir except log file Files.walkFileTree(new File(mongoLauncher.getDbPath()).toPath(), new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (!file.startsWith(mongoLauncher.getLogPath())) { Files.delete(file); } return FileVisitResult.CONTINUE; } @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { try { Files.delete(dir); } catch (DirectoryNotEmptyException ignored) { } return FileVisitResult.CONTINUE; } }); mongoLauncher = null; } }