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:net.sourceforge.pmd.docs.RuleDocGeneratorTest.java
@After public void cleanup() throws IOException { Files.walkFileTree(root, new SimpleFileVisitor<Path>() { @Override//from w ww .j a va 2s.co 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.global.canvas.services.impl.StorageServiceImpl.java
@PostConstruct public void init() throws IOException { Path directory = Paths.get("/tmp/canvas/"); Files.walkFileTree(directory, new SimpleFileVisitor<Path>() { @Override//from ww w.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; } }); System.out.println("Dir deleted.. let's create it now.."); File dir = new File("/tmp/canvas/"); boolean created = dir.mkdir(); }
From source file:org.bonitasoft.platform.configuration.util.ConfigurationResourceVisitor.java
@Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { return FileVisitResult.CONTINUE; }
From source file:org.apdplat.superword.extract.SynonymAntonymExtractor.java
public static Set<SynonymAntonym> parseDir(String dir) { Set<SynonymAntonym> data = new HashSet<>(); LOGGER.info("?" + dir); try {// w w w . ja va 2 s. com Files.walkFileTree(Paths.get(dir), new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { data.addAll(parseFile(file.toFile().getAbsolutePath())); return FileVisitResult.CONTINUE; } }); } catch (IOException e) { LOGGER.error("?", e); } return data; }
From source file:energy.usef.environment.tool.util.FileUtil.java
public static void removeFolders(String folderName) throws IOException { if (folderName == null || folderName.isEmpty() || folderName.trim().equals("\\") || folderName.trim().equals("/")) { LOGGER.warn("Prevent to delete folders recursively from the root location."); } else {//from ww w .jav a2 s . com Path directory = Paths.get(folderName); 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 { LOGGER.debug("Removing folder " + dir); Files.delete(dir); return FileVisitResult.CONTINUE; } }); } }
From source file:org.eclipse.vorto.codegen.api.CopyResourceTask.java
public void generate(Context metaData, IMappingContext mappingContext, final IGeneratedWriter outputter) { try {/* w w w.j a v a 2s . c o m*/ Path start = Paths.get(basePath.toURI()); Files.walkFileTree(start, 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 { outputter.write(new Generated(file.getFileName().toFile().getName(), getOutputPath(file).isEmpty() ? null : getOutputPath(file), FileUtils.readFileToByteArray((file.toFile())))); 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; } }); } catch (IOException ioEx) { throw new RuntimeException(ioEx); } catch (URISyntaxException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:util.ManageResults.java
/** * /*from w w w . j a v a 2 s . c o m*/ * @param instances * @param algorithms * @return the paths containing the results based on the instances and algorithms passed */ static List<Path> getPaths(List<String> instances, List<String> algorithms) { final List<Path> paths = new ArrayList<>(); for (String instance : instances) { for (String algorithm : algorithms) { String path = "experiment/" + instance + "/" + algorithm; try { Path startPath = Paths.get(path); Files.walkFileTree(startPath, new SimpleFileVisitor<Path>() { @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) { //System.out.println("Dir: " + dir.toString()); return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { //System.out.println("File: " + file.toString()); if (!file.getFileName().toString().contains("KruskalWallisResults") && !file.getFileName().toString().contains("Hypervolume_Results")) { Path currentPath = file.getParent(); if (!paths.contains(currentPath)) { paths.add(currentPath); } } return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFileFailed(Path file, IOException e) { return FileVisitResult.CONTINUE; } }); } catch (IOException e) { e.printStackTrace(); } } } return paths; }
From source file:com.ejisto.util.visitor.ConditionMatchingCopyFileVisitor.java
@Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (isCopyAllowed(file, options)) { copy(file);// w w w. j a va 2 s .c o m } return FileVisitResult.CONTINUE; }
From source file:com.yqboots.fss.util.ZipUtils.java
/** * Compresses the specified directory to a zip file * * @param dir the directory to compress/*from w w w. j a v a 2 s . c om*/ * @return the compressed file * @throws IOException */ public static Path compress(Path dir) throws IOException { Assert.isTrue(Files.exists(dir), "The directory does not exist: " + dir.toAbsolutePath()); Assert.isTrue(Files.isDirectory(dir), "Should be a directory: " + dir.toAbsolutePath()); Path result = Paths.get(dir.toAbsolutePath() + FileType.DOT_ZIP); try (final ZipOutputStream out = new ZipOutputStream( new BufferedOutputStream(new FileOutputStream(result.toFile())))) { // out.setMethod(ZipOutputStream.DEFLATED); final byte data[] = new byte[BUFFER]; // get a list of files from current directory Files.walkFileTree(dir, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(final Path path, final BasicFileAttributes attrs) throws IOException { final File file = path.toFile(); // compress to relative directory, not absolute final String root = StringUtils.substringAfter(file.getParent(), dir.toString()); try (final BufferedInputStream origin = new BufferedInputStream(new FileInputStream(file), BUFFER)) { final ZipEntry entry = new ZipEntry(root + File.separator + path.getFileName()); out.putNextEntry(entry); int count; while ((count = origin.read(data, 0, BUFFER)) != -1) { out.write(data, 0, count); } } return FileVisitResult.CONTINUE; } }); } return result; }
From source file:org.neo4j.io.fs.FileUtils.java
public static void deletePathRecursively(Path path) throws IOException { Files.walkFileTree(path, new SimpleFileVisitor<Path>() { @Override/*from w w w .j a v a 2 s .c om*/ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { deleteFileWithRetries(file, 0); return FileVisitResult.CONTINUE; } @Override public FileVisitResult postVisitDirectory(Path dir, IOException e) throws IOException { if (e != null) { throw e; } Files.delete(dir); return FileVisitResult.CONTINUE; } }); }