Skip to content

Instantly share code, notes, and snippets.

@thomo
Created November 10, 2017 15:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomo/bbe3ba9c8a2e4a9d2568827cf55803a0 to your computer and use it in GitHub Desktop.
Save thomo/bbe3ba9c8a2e4a9d2568827cf55803a0 to your computer and use it in GitHub Desktop.
Java Demo Code
public class DirectoryCollector implements Collector {
private final PlainFileFilter fileFilter;
public DirectoryCollector(PlainFileFilter ff) {
fileFilter = ff;
}
@Override
public List<FileData> collect(Path path) {
List<FileData> data = new ArrayList<>();
try (DirectoryStream<Path> ds = Files.newDirectoryStream(path)) {
for (Path p : ds) {
if (Files.isDirectory(p, LinkOption.NOFOLLOW_LINKS)) {
data.addAll(new DirectoryCollector(fileFilter).collect(p));
} else {
if (fileFilter.accept(p.toFile())) {
data.addAll(new FileCollector().collect(p));
}
}
}
} catch (IOException ex) {
System.err.println(ex.getMessage());
}
return data;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment