0
基於之前的過濾結果,可以如何簡化流搜索?基於之前的過濾結果,可以如何簡化流搜索?
HashMap<Boolean, List<Path>> result = (HashMap<Boolean, List<Path>>) Files.walk(Paths.get(folder)).map(Path
::toAbsolutePath).collect(Collectors.groupingBy(Files::isSymbolicLink));
result.get(true).stream().filter(path -> {
try {
return !result.get(false).contains(Files.readSymbolicLink(path));
} catch (IOException e) {
throw Throwables.propagate(e);
}
}).forEach(symbolicLink -> {
try {
result.get(false).addAll(Files.walk(symbolicLink, FileVisitOption.FOLLOW_LINKS).collect(Collectors
.toList()));
} catch (IOException e) {
throw Throwables.propagate(e);
}
});
return result.get(false).stream().filter(Files::isRegularFile).distinct().collect(Collectors.toList());