本文整理了Java中java.nio.file.Files.walk()
方法的一些代码示例,展示了Files.walk()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Files.walk()
方法的具体详情如下:
包路径:java.nio.file.Files
类名称:Files
方法名:walk
暂无
代码示例来源:origin: siacs/Conversations
@SuppressWarnings("StreamResourceLeak")
private final Stream<Path> cacheContent() {
try {
return Files.walk(cacheDirectory).filter(Files::isRegularFile);
} catch (final IOException e) {
throw new UncheckedIOException(e);
}
}
代码示例来源:origin: linlinjava/litemall
@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);
}
}
代码示例来源:origin: GoogleContainerTools/jib
/**
* 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());
}
}
}
代码示例来源:origin: pmd/pmd
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);
}
}
代码示例来源:origin: jooby-project/jooby
@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());
}
}
代码示例来源:origin: apache/flink
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 + ".");
}
}
代码示例来源:origin: apache/incubator-pinot
@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);
}
}
代码示例来源:origin: ata4/disunity
@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);
}
}
代码示例来源:origin: uber/okbuck
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) {
}
}
}
代码示例来源:origin: spotbugs/spotbugs
public JrtfsCodeBaseIterator() {
try {
iterator = Files.walk(root).filter(p -> isClassFile(p)).iterator();
} catch (IOException e) {
e.printStackTrace();
}
}
代码示例来源:origin: checkstyle/checkstyle
private static void walk(Path path, Consumer<Path> action) throws IOException {
try (Stream<Path> walk = Files.walk(path)) {
walk.forEach(action);
}
}
代码示例来源:origin: jooby-project/jooby
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);
}
}
代码示例来源:origin: apache/flink
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);
}
}
}
代码示例来源:origin: apache/groovy
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());
}
代码示例来源:origin: OpenHFT/Chronicle-Queue
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);
}
代码示例来源:origin: confluentinc/ksql
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);
}
}
代码示例来源:origin: oblac/jodd
@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();
}
代码示例来源:origin: oblac/jodd
@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();
}
代码示例来源:origin: oblac/jodd
@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();
}
代码示例来源:origin: neo4j/neo4j
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 );
}
内容来源于网络,如有侵权,请联系作者删除!