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.upplication.s3fs.util.AmazonS3ClientMock.java
public void clear() { try {//from w ww. ja v a2 s .co m Files.walkFileTree(base, new SimpleFileVisitor<Path>() { @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { if (dir != base) Files.delete(dir); return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Files.delete(file); return FileVisitResult.CONTINUE; } }); } catch (IOException e) { e.printStackTrace(); } }
From source file:org.schedulesdirect.grabber.Grabber.java
private void removeExpiredSchedules(FileSystem vfs) throws IOException, JSONException { final int[] i = new int[] { 0 }; final Path root = vfs.getPath("schedules"); Files.walkFileTree(root, new FileVisitor<Path>() { @Override//from www . j a v a2 s . co m public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { return !Files.isSameFile(dir, root) ? FileVisitResult.SKIP_SUBTREE : FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { try (InputStream ins = Files.newInputStream(file)) { JSONArray sched = Config.get().getObjectMapper() .readValue(IOUtils.toString(ins, ZipEpgClient.ZIP_CHARSET.toString()), JSONObject.class) .getJSONArray("programs"); if (isScheduleExpired(sched)) { Files.delete(file); ++i[0]; } } return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException { return FileVisitResult.CONTINUE; } @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { return FileVisitResult.CONTINUE; } }); LOG.info(String.format("Removed %d expired schedule(s).", i[0])); }
From source file:org.eclipse.cdt.arduino.core.internal.board.ArduinoManager.java
public static void recursiveDelete(Path directory) throws IOException { Files.walkFileTree(directory, new SimpleFileVisitor<Path>() { @Override/*from w ww. j a v a 2s .c o m*/ 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.kurento.test.services.KmsService.java
private void deleteFolderAndContent(Path folder) throws IOException { if (folder != null) { Files.walkFileTree(folder, new SimpleFileVisitor<Path>() { @Override//from w ww .j av a2 s . c om 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.schedulesdirect.grabber.Grabber.java
private void removeUnusedPrograms(FileSystem vfs) throws IOException { final int[] i = new int[] { 0 }; final Path root = vfs.getPath("programs"); Files.walkFileTree(root, new FileVisitor<Path>() { @Override/*from w ww . j a v a 2s.c o m*/ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { return !Files.isSameFile(root, dir) ? FileVisitResult.SKIP_SUBTREE : FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { String id = file.getName(file.getNameCount() - 1).toString(); id = id.substring(0, id.indexOf('.')); if (!activeProgIds.contains(id)) { if (LOG.isDebugEnabled()) LOG.debug(String.format("CacheCleaner: Unused '%s'", id)); Files.delete(file); ++i[0]; } return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException { return FileVisitResult.CONTINUE; } @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { return FileVisitResult.CONTINUE; } }); LOG.info(String.format("Removed %d unused program(s).", i[0])); }
From source file:org.schedulesdirect.grabber.Grabber.java
private void removeIgnoredStations(FileSystem vfs) throws IOException { final int[] i = new int[] { 0 }; final Path root = vfs.getPath("schedules"); Files.walkFileTree(root, new FileVisitor<Path>() { @Override// www . j a v a 2s . c o m public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { return !Files.isSameFile(root, dir) ? FileVisitResult.SKIP_SUBTREE : FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { String id = file.getName(file.getNameCount() - 1).toString(); id = id.substring(0, id.indexOf('.')); if (stationList != null && !stationList.contains(id)) { if (LOG.isDebugEnabled()) LOG.debug(String.format("CacheCleaner: Remove '%s'", id)); Files.delete(file); ++i[0]; } return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException { return FileVisitResult.CONTINUE; } @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { return FileVisitResult.CONTINUE; } }); LOG.info(String.format("Removed %d ignored station(s).", i[0])); }
From source file:fr.pilato.elasticsearch.crawler.fs.test.integration.FsCrawlerImplAllParametersIT.java
/** * Test case for #95: https://github.com/dadoonet/fscrawler/issues/95 : Folder index is not getting delete on delete of folder *//* ww w. j a va2 s . c om*/ @Test public void test_remove_folder_deleted_enabled() throws Exception { Fs fs = startCrawlerDefinition().setRemoveDeleted(true).build(); startCrawler(getCrawlerName(), fs, endCrawlerDefinition(getCrawlerName()), null); // We should have 7 docs first countTestHelper(getCrawlerName(), null, 7, currentTestResourceDir); logContentOfDir(currentTestResourceDir, Level.DEBUG); // We remove a directory logger.info(" ---> Removing dir subdir1"); Files.walkFileTree(currentTestResourceDir.resolve("subdir1"), 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; } }); logContentOfDir(currentTestResourceDir, Level.DEBUG); // We expect to have 4 docs now countTestHelper(getCrawlerName(), null, 4, currentTestResourceDir); }
From source file:org.tinymediamanager.core.Utils.java
/** * Deletes a complete directory recursively, using Java NIO * /*from www. java 2s . c om*/ * @param dir * directory to delete * @throws IOException */ public static void deleteDirectoryRecursive(Path dir) throws IOException { if (!Files.exists(dir)) { return; } LOGGER.info("Deleting complete directory: " + dir); Files.walkFileTree(dir, new FileVisitor<Path>() { @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { Files.delete(dir); return FileVisitResult.CONTINUE; } @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.warn("Could not delete " + file + "; " + exc.getMessage()); return FileVisitResult.CONTINUE; } }); }
From source file:org.tinymediamanager.core.Utils.java
/** * Unzips the specified zip file to the specified destination directory. Replaces any files in the destination, if they already exist. * //from w ww .j a va 2 s.com * @param zipFile * the name of the zip file to extract * @param destDir * the directory to unzip to * @throws IOException */ public static void unzip(Path zipFile, final Path destDir) { Map<String, String> env = new HashMap<>(); try { // if the destination doesn't exist, create it if (!Files.exists(destDir)) { Files.createDirectories(destDir); } // check if file exists env.put("create", String.valueOf(!Files.exists(zipFile))); // use a Zip filesystem URI URI fileUri = zipFile.toUri(); // here URI zipUri = new URI("jar:" + fileUri.getScheme(), fileUri.getPath(), null); try (FileSystem zipfs = FileSystems.newFileSystem(zipUri, env)) { final Path root = zipfs.getPath("/"); // walk the zip file tree and copy files to the destination Files.walkFileTree(root, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { final Path destFile = Paths.get(destDir.toString(), file.toString()); LOGGER.debug("Extracting file {} to {}", file, destFile); Files.copy(file, destFile, StandardCopyOption.REPLACE_EXISTING); return FileVisitResult.CONTINUE; } @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { final Path dirToCreate = Paths.get(destDir.toString(), dir.toString()); if (!Files.exists(dirToCreate)) { LOGGER.debug("Creating directory {}", dirToCreate); Files.createDirectory(dirToCreate); } return FileVisitResult.CONTINUE; } }); } } catch (Exception e) { LOGGER.error("Failed to create zip file!" + e.getMessage()); } }
From source file:org.roda.core.RodaCoreFactory.java
public static Set<String> getFilenamesInsideConfigFolder(String folder) throws IOException { Set<String> fileNames = new HashSet<>(); // get from external config Set<String> externalFileNames = new HashSet<>(); Path configPath = RodaCoreFactory.getConfigPath().resolve(folder); Files.walkFileTree(configPath, new SimpleFileVisitor<Path>() { @Override// www . jav a2 s .c om public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { externalFileNames.add(file.getFileName().toString()); return FileVisitResult.CONTINUE; } }); fileNames.addAll(externalFileNames); // get from internal config List<ClassLoader> classLoadersList = new LinkedList<>(); classLoadersList.add(ClasspathHelper.contextClassLoader()); Set<String> internalFilesPath = new Reflections(new ConfigurationBuilder() .filterInputsBy(new FilterBuilder() .include(FilterBuilder.prefix("" + RodaConstants.CORE_CONFIG_FOLDER + "/" + folder))) .setScanners(new ResourcesScanner()) .setUrls(ClasspathHelper.forClassLoader(classLoadersList.toArray(new ClassLoader[0])))) .getResources(Pattern.compile(".*")); for (String internalFilePath : internalFilesPath) { fileNames.add(Paths.get(internalFilePath).getFileName().toString()); } return fileNames; }