@SuppressWarnings("StreamResourceLeak") private final Stream<Path> cacheContent() { try { return Files.walk(cacheDirectory).filter(Files::isRegularFile); } catch (final IOException e) { throw new UncheckedIOException(e); } }
@Override public Stream<Path> loadAll() { try { return Files.walk(rootLocation, 1) .filter(path -> !path.equals(rootLocation)) .map(path -> rootLocation.relativize(path)); } catch (IOException e) { throw new RuntimeException("Failed to read stored files", e); } }
/** * Walks {@link #rootDir}. * * @return the walked files. * @throws IOException if walking the files fails. */ public ImmutableList<Path> walk() throws IOException { try (Stream<Path> fileStream = Files.walk(rootDir)) { return fileStream.filter(pathFilter).sorted().collect(ImmutableList.toImmutableList()); } } }
private List<Path> listMdFiles(Path pagesDirectory) { try { return Files.walk(pagesDirectory) .filter(Files::isRegularFile) .filter(path -> path.toString().endsWith(".md")) .collect(Collectors.toList()); } catch (IOException ex) { throw new RuntimeException("error listing files in " + pagesDirectory, ex); } }
@Override public Iterable<Path> children(final Path handle) throws IOException { try (Stream<Path> walk = Files.walk(handle)) { return walk .skip(1) .filter(filter) .collect(Collectors.toList()); } }
public void copyOptJarsToLib(String jarNamePrefix) throws FileNotFoundException, IOException { final Optional<Path> reporterJarOptional; try (Stream<Path> logFiles = Files.walk(opt)) { reporterJarOptional = logFiles .filter(path -> path.getFileName().toString().startsWith(jarNamePrefix)) .findFirst(); } if (reporterJarOptional.isPresent()) { final Path optReporterJar = reporterJarOptional.get(); final Path libReporterJar = lib.resolve(optReporterJar.getFileName()); Files.copy(optReporterJar, libReporterJar); filesToDelete.add(new AutoClosablePath(libReporterJar)); } else { throw new FileNotFoundException("No jar could be found matching the pattern " + jarNamePrefix + "."); } }
@Override public String[] listFiles(URI fileUri, boolean recursive) throws IOException { File file = new File(decodeURI(fileUri.getRawPath())); if (!recursive) { return Arrays.stream(file.list()).map(s -> new File(file, s)).map(File::getAbsolutePath).toArray(String[]::new); } else { return Files.walk(Paths.get(fileUri)). filter(s -> !s.equals(file.toPath())).map(Path::toString).toArray(String[]::new); } }
@Override protected void runFile(Path file) { if (Files.isDirectory(file) && recursive) { try { Files.walk(file, maxDepth, FOLLOW_LINKS) .filter(this::fileFilter) .forEach(this::runFileRecursive); } catch (IOException ex) { L.log(Level.WARNING, "Can't walk directory " + file, ex); } } else { runFileRecursive(file); } }
static void deleteDirectory(File path) { try (Stream<Path> walk = Files.walk(path.toPath(), FileVisitOption.FOLLOW_LINKS)) { walk.sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete); } catch (IOException ignored) { } } }
public JrtfsCodeBaseIterator() { try { iterator = Files.walk(root).filter(p -> isClassFile(p)).iterator(); } catch (IOException e) { e.printStackTrace(); } }
private static void walk(Path path, Consumer<Path> action) throws IOException { try (Stream<Path> walk = Files.walk(path)) { walk.forEach(action); } }
public boolean exists(final Predicate<Path> filter) { try (Stream<Path> walk = Try.apply(() -> Files.walk(root)).orElse(Stream.empty())) { return walk .skip(1) .anyMatch(filter); } }
private static List<Path> listRecursively(final Path dir) { try { if (!Files.exists(dir)) { return Collections.emptyList(); } else { try (Stream<Path> files = Files.walk(dir, FileVisitOption.FOLLOW_LINKS)) { return files.filter(Files::isRegularFile).collect(Collectors.toList()); } } } catch (IOException e) { throw new RuntimeException(e); } } }
public ScriptCompilationExecuter(File[] sourceDirectories, final List<URL> classpath) throws IOException { this.classpath = classpath.toArray(new URL[classpath.size()]); Set<File> sources = new HashSet<>(); for (File sourceDirectory : sourceDirectories) { Files.walk(sourceDirectory.toPath()) .filter(path -> { File file = path.toFile(); return file.isFile() && file.getName().endsWith(".groovy"); }) .forEach(path -> sources.add(path.toFile())); } this.sources = sources.toArray(new File[sources.size()]); System.out.println("sources = " + sources.size()); }
public void before() throws Exception { Path rootPath = Paths.get(basePath); Files.walk(rootPath, FileVisitOption.FOLLOW_LINKS) .sorted(Comparator.reverseOrder()) .map(Path::toFile) .peek(System.out::println) .forEach(File::delete); }
private static List<Class<?>> findClasses(final Path directory, final String packageName) { if (!directory.toFile().exists()) { return Collections.emptyList(); } try (final Stream<Path> paths = Files.walk(directory)) { return paths .filter(Files::isRegularFile) .filter(CLASS_MATCHER::matches) .map(path -> parseClass(packageName, path)) .collect(Collectors.toList()); } catch (final Exception e) { throw new AssertionError("Failed to load classes in directory: " + directory, e); } }
@BeforeAll public static void beforeAll() throws Exception { if (BASE_DIR.exists()) { // clean up all subdirs & files Files.walk(BASE_DIR.toPath(),FileVisitOption.FOLLOW_LINKS) .sorted(Comparator.reverseOrder()) .map(Path::toFile) .peek(System.out::println) .forEach(File::delete); } // created directory is needed for tests BASE_DIR.mkdirs(); }
@BeforeAll static void beforeAll() throws Exception { if (BASE_DIR.exists()) { // clean up all subdirs & files Files.walk(BASE_DIR.toPath(), FileVisitOption.FOLLOW_LINKS) .sorted(Comparator.reverseOrder()) .map(Path::toFile) .peek(System.out::println) .forEach(File::delete); } // created directory is needed for tests BASE_DIR.mkdirs(); }
@BeforeAll public static void beforeAll() throws Exception { if (BASE_DIR.exists()) { // clean up all subdirs & files Files.walk(BASE_DIR.toPath(), FileVisitOption.FOLLOW_LINKS) .sorted(Comparator.reverseOrder()) .map(Path::toFile) .peek(System.out::println) .forEach(File::delete); } // created directory is needed for tests BASE_DIR.mkdirs(); }
private Map<Path, Description> describeRecursively( Path directory ) throws IOException { return Files.walk( directory ) .map( path -> pair( directory.relativize( path ), describe( path ) ) ) .collect( HashMap::new, ( pathDescriptionHashMap, pathDescriptionPair ) -> pathDescriptionHashMap.put( pathDescriptionPair.first(), pathDescriptionPair.other() ), HashMap::putAll ); }