Created
November 10, 2017 15:33
-
-
Save thomo/bbe3ba9c8a2e4a9d2568827cf55803a0 to your computer and use it in GitHub Desktop.
Java Demo Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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