Java Code Examples for java.nio.file.FileVisitResult

The following examples show how to use java.nio.file.FileVisitResult. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attributes) throws IOException {
    String filePath = file.toString().replaceAll("\\\\", "/");
    filePath = filePath.replace(prefix, "");
    Optional<app.jweb.file.domain.File> optional = fileService.findByPath(filePath);
    if (!optional.isPresent()) {
        File realFile = file.toFile();
        String directoryPath = parent(filePath);
        CreateFileRequest createFileRequest = new CreateFileRequest();
        createFileRequest.directoryId = map.get(directoryPath).id;
        createFileRequest.path = filePath;
        createFileRequest.length = realFile.length();
        createFileRequest.fileName = realFile.getName();
        createFileRequest.requestBy = "synchronized";
        fileService.create(createFileRequest);
    }
    return FileVisitResult.CONTINUE;
}
 
Example 2
Source Project: che   Source File: ZipUtilsWriteTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@AfterMethod
public void tearDown() throws IOException {
  Files.delete(zipFile);
  Files.walkFileTree(
      tempDir,
      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 e) throws IOException {
          if (e == null) {
            Files.delete(dir);
            return FileVisitResult.CONTINUE;
          } else {
            throw e;
          }
        }
      });
}
 
Example 3
private static void deletePath(final Path path) throws IOException {
    if (Files.isDirectory(path)) {
        Files.walkFileTree(path, new SimpleFileVisitor<Path>() {
            @Override
            public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException {
                Files.deleteIfExists(file);
                return FileVisitResult.CONTINUE;
            }

            @Override
            public FileVisitResult postVisitDirectory(final Path dir, final IOException exc) throws IOException {
                Files.deleteIfExists(dir);
                return FileVisitResult.CONTINUE;
            }
        });
    } else {
        Files.deleteIfExists(path);
    }
}
 
Example 4
Source Project: ipst   Source File: EurostagDDB.java    License: Mozilla Public License 2.0 6 votes vote down vote up
EurostagDDB(List<Path> ddbDirs) throws IOException {
    for (Path ddbDir : ddbDirs) {
        ddbDir = readSymbolicLink(ddbDir);
        if (!Files.exists(ddbDir) && !Files.isDirectory(ddbDir)) {
            throw new IllegalArgumentException(ddbDir + " must exist and be a dir");
        }
        Files.walkFileTree(ddbDir, EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, new SimpleFileVisitor<Path>() {
            @Override
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                String fileName = file.getFileName().toString();
                Path tmpfile = readSymbolicLink(file);
                if (Files.isDirectory(tmpfile)) {
                    Files.walkFileTree(tmpfile, EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, this);
                } else if (Files.isRegularFile(tmpfile) && fileName.endsWith(".tg")) {
                    String key = fileName.substring(0, fileName.length() - 3);
                    if (generators.containsKey(key)) {
                        LOGGER.warn("the processing has detected that the file {} is present in {} and {}", fileName, tmpfile, generators.get(key));
                    }
                    generators.put(key, tmpfile);
                }
                return super.visitFile(file, attrs);
            }
        });
    }
}
 
Example 5
Source Project: airfield   Source File: TakeDownIT.java    License: Apache License 2.0 6 votes vote down vote up
@Before
public void init() throws IOException {
    Path directory = Paths.get(LOCAL_REPO);
    if (Files.exists(directory)) {
        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 {
                Files.delete(dir);
                return FileVisitResult.CONTINUE;
            }

        });
    }
    this.cut = new TakeDown(LOCAL_REPO, "git://localhost:4242/");
}
 
Example 6
Source Project: openjdk-jdk8u   Source File: IterationCount.java    License: GNU General Public License v2.0 6 votes vote down vote up
private static void deleteDir(Path directory) throws IOException {
    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 {
            Files.delete(dir);
            return FileVisitResult.CONTINUE;
        }
    });
}
 
Example 7
Source Project: Java-Coding-Problems   Source File: MoveFileVisitor.java    License: MIT License 6 votes vote down vote up
@Override
public FileVisitResult preVisitDirectory(Object dir, BasicFileAttributes attrs) throws IOException {
    
    System.out.println("Move directory: " + (Path) dir);
    
    Path newDir = moveTo.resolve(moveFrom.relativize((Path) dir));
    try {
        Files.copy((Path) dir, newDir, REPLACE_EXISTING, COPY_ATTRIBUTES);
        time = Files.getLastModifiedTime((Path) dir);
    } catch (IOException e) {
        System.err.println("Unable to move " + newDir + " [" + e + "]");
        
        return FileVisitResult.SKIP_SUBTREE;
    }

    return FileVisitResult.CONTINUE;
}
 
Example 8
Source Project: setupmaker   Source File: NugetProcessCompiler.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Delete all files under a target directory
 * @param path: folder containing spec files
 * @throws IOException
 */
public void cleanDir(String path) throws IOException {
    Path directory = Paths.get(path);
    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 {
            Files.delete(dir);
            return FileVisitResult.CONTINUE;
        }

    });
}
 
Example 9
Source Project: cxf   Source File: WSDLToIDLTest.java    License: Apache License 2.0 6 votes vote down vote up
@After
public void tearDown() throws Exception {
    super.tearDown();

    Files.walkFileTree(output, 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;
        }
    });
    output = null;
}
 
Example 10
Source Project: buck   Source File: DefaultFilteredDirectoryCopier.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void copyDir(ProjectFilesystem filesystem, Path srcDir, Path destDir, Predicate<Path> pred)
    throws IOException {

  // Remove existing contents if any.
  if (filesystem.exists(destDir)) {
    filesystem.deleteRecursivelyIfExists(destDir);
  }
  filesystem.mkdirs(destDir);

  filesystem.walkRelativeFileTree(
      srcDir,
      new SimpleFileVisitor<Path>() {
        @Override
        public FileVisitResult visitFile(Path srcPath, BasicFileAttributes attributes)
            throws IOException {
          if (pred.test(srcPath)) {
            Path destPath = destDir.resolve(srcDir.relativize(srcPath));
            filesystem.createParentDirs(destPath);
            filesystem.copy(srcPath, destPath, CopySourceMode.FILE);
          }
          return FileVisitResult.CONTINUE;
        }
      });
}
 
Example 11
@Before
public void before() throws Exception {

    // Clean up old files.
    if (Files.isDirectory(archiveDir.toPath())) {
        Files.walkFileTree(archiveDir.toPath(), new SimpleFileVisitor<Path>(){
            @Override
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                Files.delete(file);
                return FileVisitResult.CONTINUE;
            }
        });
    }

    // Create original flow.xml.gz
    Files.createDirectories(flowFile.getParentFile().toPath());
    try (OutputStream os = Files.newOutputStream(flowFile.toPath(),
            StandardOpenOption.CREATE, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING)) {
        // 10 bytes.
        os.write("0123456789".getBytes());
    }

}
 
Example 12
Source Project: flow   Source File: ApplicationRunnerServlet.java    License: Apache License 2.0 6 votes vote down vote up
private void addDirectories(File parent, Set<String> packages)
        throws IOException {
    Path root = parent.toPath();
    Files.walkFileTree(parent.toPath(), new SimpleFileVisitor<Path>() {

        @Override
        public FileVisitResult postVisitDirectory(Path dir, IOException exc)
                throws IOException {
            File file = dir.toFile();
            if (file.isDirectory()) {
                Path relative = root.relativize(file.toPath());
                packages.add(relative.toString().replace(File.separatorChar,
                        '.'));
            }
            return super.postVisitDirectory(dir, exc);
        }
    });
}
 
Example 13
Source Project: commerce-gradle-plugin   Source File: TestUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static void generateDummyPlatform(Path destination, String version) throws IOException, URISyntaxException {
    Path targetZip = destination.resolve(String.format("hybris-commerce-suite-%s.zip", version));
    Map<String, String> env = new HashMap<>();
    env.put("create", "true");
    try (FileSystem zipfs = FileSystems.newFileSystem(URI.create("jar:" + targetZip.toUri().toString()), env, null)) {
        Path sourceDir = Paths.get(TestUtils.class.getResource("/dummy-platform").toURI());
        Files.walkFileTree(sourceDir, new SimpleFileVisitor<Path>() {
            @Override
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                Path relative = sourceDir.relativize(file);
                if (relative.getParent() != null) {
                    Path path = zipfs.getPath(relative.getParent().toString());
                    Files.createDirectories(path);
                }
                Path target = zipfs.getPath(relative.toString());
                Files.copy(file, target);
                return super.visitFile(file, attrs);
            }
        });
        String build = String.format("version=%s\n", version);
        Path buildNumber = zipfs.getPath("hybris", "bin", "platform", "build.number");
        Files.write(buildNumber, build.getBytes(), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
    }
}
 
Example 14
Source Project: Launcher   Source File: CertificateManager.java    License: GNU General Public License v3.0 6 votes vote down vote up
public void readTrustStore(Path dir) throws IOException, CertificateException {
    if (!IOHelper.isDir(dir)) {
        Files.createDirectories(dir);
        try (OutputStream outputStream = IOHelper.newOutput(dir.resolve("GravitCentralRootCA.crt"));
             InputStream inputStream = IOHelper.newInput(IOHelper.getResourceURL("pro/gravit/launchserver/defaults/GravitCentralRootCA.crt"))) {
            IOHelper.transfer(inputStream, outputStream);
        }
    }
    List<X509Certificate> certificates = new ArrayList<>();
    CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
    IOHelper.walk(dir, new SimpleFileVisitor<Path>() {
        @Override
        public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
            if (file.toFile().getName().endsWith(".crt")) {
                try (InputStream inputStream = IOHelper.newInput(file)) {
                    certificates.add((X509Certificate) certFactory.generateCertificate(inputStream));
                } catch (CertificateException e) {
                    throw new IOException(e);
                }
            }
            return super.visitFile(file, attrs);
        }
    }, false);
    trustManager = new LauncherTrustManager(certificates.toArray(new X509Certificate[0]));
}
 
Example 15
Source Project: logbook-kai   Source File: BattleLogs.java    License: MIT License 6 votes vote down vote up
@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
    // ルートディレクトリかチェック
    if (this.baseDir.equals(dir)) {
        return FileVisitResult.CONTINUE;
    }
    // 年月のフォルダかチェック
    String dirName = dir.getFileName().toString();
    if (!isExpectedDirectoryName(dirName)) {
        return FileVisitResult.SKIP_SUBTREE;
    }
    // 年月部分を比較
    if (dirName.compareTo(this.expired.substring(0, dirName.length())) > 0) {
        return FileVisitResult.SKIP_SUBTREE;
    }
    return FileVisitResult.CONTINUE;
}
 
Example 16
Source Project: PeerWasp   Source File: FileWalker.java    License: MIT License 6 votes vote down vote up
@Override
public FileVisitResult visitFile(Path path, BasicFileAttributes attr) throws IOException {
	if(PathUtils.isFileHidden(path)){
		return FileVisitResult.CONTINUE;
	}
	if (throwCreates) {
		eventManager.onLocalFileCreated(path);
	} else {
		if (Files.isDirectory(path)) {
			FolderComposite newFolder = new FolderComposite(path, false);
			newFolder.setIsSynchronized(true);
			fileTree.putComponent(path, newFolder);
		} else {
			FileLeaf newFile = new FileLeaf(path, false);
			newFile.setIsSynchronized(true);
			fileTree.putComponent(path, newFile);
		}
	}

	return FileVisitResult.CONTINUE;
}
 
Example 17
Source Project: atomix   Source File: FileTesting.java    License: Apache License 2.0 6 votes vote down vote up
public static void cleanFiles() {
  Path directory = Paths.get("target/test-files/");
  try {
    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 {
        Files.delete(dir);
        return FileVisitResult.CONTINUE;
      }
    });
  } catch (Exception ignore) {
  }
}
 
Example 18
Source Project: atomix   Source File: RaftStorageTest.java    License: Apache License 2.0 6 votes vote down vote up
@Before
@After
public void cleanupStorage() throws IOException {
  if (Files.exists(PATH)) {
    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;
      }
    });
  }
}
 
Example 19
protected static void deleteRecursively(final Path path) throws IOException {
    if (Files.exists(path)) {
        if (Files.isDirectory(path)) {
            Files.walkFileTree(path, new SimpleFileVisitor<Path>() {
                @Override
                public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException {
                    Files.deleteIfExists(file);
                    return FileVisitResult.CONTINUE;
                }

                @Override
                public FileVisitResult postVisitDirectory(final Path dir, final IOException exc) throws IOException {
                    Files.deleteIfExists(dir);
                    return FileVisitResult.CONTINUE;
                }
            });
        } else {
            Files.deleteIfExists(path);
        }
    }
}
 
Example 20
Source Project: nexus-public   Source File: DirectoryHelper.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Empties an existing directory, by recursively removing all it's siblings, regular files and directories. Accepts
 * only existing directories, and when returns, it's guaranteed that passed in directory will be emptied (will
 * have no siblings, not counting OS specific ones, will be "empty" as per current OS is empty defined).
 */
public static void empty(final Path dir) throws IOException {
  validateDirectory(dir);
  Files.walkFileTree(dir, DEFAULT_FILE_VISIT_OPTIONS, Integer.MAX_VALUE,
      new SimpleFileVisitor<Path>()
      {
        @Override
        public FileVisitResult visitFile(final Path f, final BasicFileAttributes attrs) throws IOException {
          Files.delete(f);
          return FileVisitResult.CONTINUE;
        }

        @Override
        public FileVisitResult postVisitDirectory(final Path d, final IOException exc) throws IOException {
          if (exc != null) {
            throw exc;
          }
          else if (dir != d) {
            Files.delete(d);
          }
          return FileVisitResult.CONTINUE;
        }
      }
  );
}
 
Example 21
Source Project: JavaRushTasks   Source File: SearchFileVisitor.java    License: MIT License 6 votes vote down vote up
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
    if (!attrs.isRegularFile()) return CONTINUE;

    if (partOfNameCheck && file.getFileName().toString().indexOf(this.partOfName) == -1)
        return CONTINUE;

    if (minSizeCheck && attrs.size() < minSize)
        return CONTINUE;

    if (maxSizeCheck && attrs.size() > maxSize)
        return CONTINUE;

    if (partOfContentCheck && new String(Files.readAllBytes(file)).indexOf(partOfContent) == -1)
        return CONTINUE;

    foundFiles.add(file);

    return CONTINUE;
}
 
Example 22
Source Project: mycore   Source File: MCRMetsSave.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * @return true if all files in the {@link org.mycore.datamodel.ifs2.MCRDirectory} appears in the fileGroup
 */
public static boolean isComplete(final FileGrp fileGroup, MCRPath rootDir) {
    final AtomicBoolean complete = new AtomicBoolean(true);
    try {
        Files.walkFileTree(rootDir, new SimpleFileVisitor<Path>() {

            @Override
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                if (!file.getFileName().toString().equals(MCRMetsSave.getMetsFileName())) {
                    MCRPath mcrPath = MCRPath.toMCRPath(file);
                    String path;
                    try {
                        path = MCRXMLFunctions
                            .encodeURIPath(mcrPath.getOwnerRelativePath().substring(1), true);//remove leading '/'
                    } catch (URISyntaxException e) {
                        throw new IOException(e);
                    }
                    if (!fileGroup.contains(path)) {
                        LOGGER.warn("{} does not appear in {}!", path, mcrPath.getOwner());
                        complete.set(false);
                        return FileVisitResult.TERMINATE;
                    }
                }
                return super.visitFile(file, attrs);
            }
        });
    } catch (Exception ex) {
        LOGGER.error("Error while validating mets", ex);
        return false;
    }

    return complete.get();
}
 
Example 23
Source Project: openjdk-8   Source File: FileTreeCreatorVC7.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) {
   //end matching attributes set by ignorepath
   wg.endTag();
   attributes.pop();

   return CONTINUE;
}
 
Example 24
Source Project: ignite   Source File: IgniteWalIteratorFactory.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * This methods checks all provided files to be correct WAL segment.
 * Header record and its position is checked. WAL position is used to determine real index.
 * File index from file name is ignored.
 *
 * @param iteratorParametersBuilder IteratorParametersBuilder.
 * @return list of file descriptors with checked header records, having correct file index is set
 */
public List<FileDescriptor> resolveWalFiles(
    IteratorParametersBuilder iteratorParametersBuilder
) {
    File[] filesOrDirs = iteratorParametersBuilder.filesOrDirs;

    if (filesOrDirs == null || filesOrDirs.length == 0)
        return Collections.emptyList();

    final FileIOFactory ioFactory = iteratorParametersBuilder.ioFactory;

    final TreeSet<FileDescriptor> descriptors = new TreeSet<>();

    for (File file : filesOrDirs) {
        if (file.isDirectory()) {
            try {
                walkFileTree(file.toPath(), new SimpleFileVisitor<Path>() {
                    @Override public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) {
                        addFileDescriptor(path.toFile(), ioFactory, descriptors);

                        return FileVisitResult.CONTINUE;
                    }
                });
            }
            catch (IOException e) {
                U.error(log, "Failed to walk directories from root [" + file + "]. Skipping this directory.", e);
            }

            continue;
        }

        addFileDescriptor(file, ioFactory, descriptors);
    }

    return new ArrayList<>(descriptors);
}
 
Example 25
Source Project: jax-maven-plugin   Source File: BaseMojo.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs){
    if (file.toString().toLowerCase().endsWith(".java")) {
        this.javaFiles.add(file.toString());
    }
    return FileVisitResult.CONTINUE;
}
 
Example 26
Source Project: camel-spring-boot   Source File: FileDeploymentUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static void deleteRecursively(Path directory) throws IOException {
    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 {
            Files.delete(dir);
            return FileVisitResult.CONTINUE;
        }
    });
}
 
Example 27
Source Project: openjdk-jdk9   Source File: JmodTask.java    License: GNU General Public License v2.0 5 votes vote down vote up
void processSection(JmodOutputStream out, Section section, Path path)
    throws IOException
{
    Files.walkFileTree(path, Set.of(FileVisitOption.FOLLOW_LINKS),
        Integer.MAX_VALUE, new SimpleFileVisitor<Path>() {
            @Override
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
                throws IOException
            {
                Path relPath = path.relativize(file);
                if (relPath.toString().equals(MODULE_INFO)
                        && !Section.CLASSES.equals(section))
                    warning("warn.ignore.entry", MODULE_INFO, section);

                if (!relPath.toString().equals(MODULE_INFO)
                        && !matches(relPath, excludes)) {
                    try (InputStream in = Files.newInputStream(file)) {
                        out.writeEntry(in, section, relPath.toString());
                    } catch (IOException x) {
                        if (x.getMessage().contains("duplicate entry")) {
                            warning("warn.ignore.duplicate.entry",
                                    relPath.toString(), section);
                            return FileVisitResult.CONTINUE;
                        }
                        throw x;
                    }
                }
                return FileVisitResult.CONTINUE;
            }
        });
}
 
Example 28
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
    Path relativePath = baseDir.relativize(file);
    byte[] content = Files.readAllBytes(file);

    if (isJavaClass(relativePath)) {
        visitClass(relativePath, content);
    } else {
        visitResource(relativePath, content);
    }

    return FileVisitResult.CONTINUE;
}
 
Example 29
Source Project: gcs   Source File: FileScanner.java    License: Mozilla Public License 2.0 5 votes vote down vote up
@Override
public FileVisitResult postVisitDirectory(Path path, IOException exception) throws IOException {
    if (exception != null) {
        Log.error(exception);
    }
    return FileVisitResult.CONTINUE;
}
 
Example 30
Source Project: Java-Coding-Problems   Source File: MoveFileVisitor.java    License: MIT License 5 votes vote down vote up
@Override
public FileVisitResult postVisitDirectory(Object dir, IOException ioe) throws IOException {
            
    Path newDir = moveTo.resolve(moveFrom.relativize((Path) dir));
    try {
        Files.setLastModifiedTime(newDir, time);
        Files.delete((Path) dir);
    } catch (IOException e) {
        System.err.println("Unable to copy all attributes to: " + newDir + " [" + e + "]");
    }

    return FileVisitResult.CONTINUE;
}
 
Example 31
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc)
		throws IOException {
	super.postVisitDirectory(dir, exc);
	delete(dir);
	return CONTINUE;
}
 
Example 32
Source Project: buck   Source File: WindowsClangCxxIntegrationTest.java    License: Apache License 2.0 5 votes vote down vote up
private ImmutableSortedSet<Path> findFiles(Path root, PathMatcher matcher) throws IOException {
  ImmutableSortedSet.Builder<Path> files = ImmutableSortedSet.naturalOrder();
  Files.walkFileTree(
      root,
      new SimpleFileVisitor<Path>() {
        @Override
        public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
          if (matcher.matches(file)) {
            files.add(file);
          }
          return FileVisitResult.CONTINUE;
        }
      });
  return files.build();
}
 
Example 33
Source Project: logging-log4j2   Source File: CleanFolders.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException {
	printf("%s Deleting file %s with %s\n", CLEANER_MARKER, file, attrs);
	final boolean deleted = Files.deleteIfExists(file);
	printf(CLEANER_MARKER, "%s Deleted file %s: %s\n", file, deleted);
	return FileVisitResult.CONTINUE;
}
 
Example 34
Source Project: Java-Coding-Problems   Source File: SearchFileVisitor.java    License: MIT License 5 votes vote down vote up
@Override
public FileVisitResult postVisitDirectory(Object dir, IOException ioe) throws IOException {
    
    if(ioe != null) {
        throw ioe;
    }
    
    System.out.println("Visited: " + (Path) dir);

    return FileVisitResult.CONTINUE;
}
 
Example 35
Source Project: baratine   Source File: IoUtil.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
  throws IOException
{
  Files.delete(file);
  
  return FileVisitResult.CONTINUE;
}
 
Example 36
Source Project: hottub   Source File: FileTreeCreatorVC10.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public FileVisitResult preVisitDirectory(Path path, BasicFileAttributes attrs)
      throws IOException {
   Boolean hide = false;
   // TODO remove attrs, if path is matched in this dir, then it is too in every subdir.
   // And we will check anyway
   DirAttributes newAttr = attributes.peek().clone();

   // check per config ignorePaths!
   for (BuildConfig cfg : allConfigs) {
      if (cfg.matchesIgnoredPath(path.toAbsolutePath().toString())) {
         newAttr.setIgnore(cfg);
      }

      // Hide is always on all configs. And additional files are never hiddden
      if (cfg.matchesHidePath(path.toAbsolutePath().toString())) {
         hide = true;
         break;
      }
   }

   if (!hide) {
      String name = startDir.relativize(path.toAbsolutePath()).toString();
      if (!"".equals(name)) {
         wg10.addFilter(name);
      }

      attributes.push(newAttr);
      return super.preVisitDirectory(path, attrs);
   } else {
      return FileVisitResult.SKIP_SUBTREE;
   }
}
 
Example 37
Source Project: chipster   Source File: ToolboxClientComp.java    License: MIT License 5 votes vote down vote up
private void fixPermissions(File jobToolboxDir) throws IOException {
	Files.walkFileTree(jobToolboxDir.toPath(), new SimpleFileVisitor<Path>() {
		@Override
		public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
			for (String extension : executableExtensions) {
				if (file.getFileName().toString().endsWith("." + extension)) {
					logger.debug("fixing permissions for " + file.getFileName());
					Files.setPosixFilePermissions(file, fi.csc. microarray.util.Files.get755Permissions());
				}
			}
			return FileVisitResult.CONTINUE;
		}
	});
}
 
Example 38
Source Project: sensorhub   Source File: FileUtils.java    License: Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Recursively deletes a folder and all its content
 * @param folder
 * @throws IOException
 */
public static void deleteRecursively(File folder) throws IOException
{
    Files.walkFileTree(folder.toPath(), new SimpleFileVisitor<Path>() {

        @Override
        public FileVisitResult postVisitDirectory(Path dir, IOException e) throws IOException
        {
            if (e == null)
            {
                Files.delete(dir);
                return FileVisitResult.CONTINUE;
            }
            else
            {
                throw e;
            }
        }

        @Override
        public FileVisitResult visitFile(Path f, BasicFileAttributes att) throws IOException
        {
            Files.delete(f);
            return FileVisitResult.CONTINUE;
        }
        
    });
}
 
Example 39
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attributes) {
    try {
        Files.copy(file, targetDir.resolve(sourceDir.relativize(file)));
    } catch (IOException ex) {
    }
    return FileVisitResult.CONTINUE;
}
 
Example 40
Source Project: steady   Source File: FilenamePatternSearch.java    License: Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public FileVisitResult visitFile(Path _f, BasicFileAttributes attrs) {
	if(!_f.toFile().isDirectory() && !this.foundFile(_f) && _f.getFileName()!=null) {
		final Matcher m = this.pattern.matcher(_f.getFileName().toString());
		if(m.matches()) {
			this.addFile(_f);
		}
	}
	return FileVisitResult.CONTINUE;
}