import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
/**
*
*/
public final class FileWatch implements Runnable {
+ private static final Logger logger = Logger.getLogger(FileWatch.class.getName());
private final Set<Path> files;
private final Set<Path> directories;
- public FileWatch(Collection<Path> dirs) throws IOException {
+ public FileWatch(Collection<Path> dirs) {
FileDir res = new FileDir();
getFileDir(dirs, res);
}
}
- private void getFileDir(Collection<Path> paths, FileDir res) throws IOException {
+ private void getFileDir(Iterable<Path> paths, FileDir result) {
for (Path p : paths) {
- getFileDir(p, res);
+ getFileDir(p, result);
}
}
- private void getFileDir(Path p, FileDir res) throws IOException {
-
- if (Files.isDirectory(p)) {
- res.dirs.add(p);
- DirectoryStream<Path> dir = Files.newDirectoryStream(p);
- for (Path pp : dir) {
- getFileDir(pp, res);
+ private void getFileDir(Path path, FileDir result) {
+ try {
+ if (Files.isDirectory(path)) {
+ result.dirs.add(path);
+ DirectoryStream<Path> dir = Files.newDirectoryStream(path);
+ getFileDir(dir, result);
+ } else if (Files.isRegularFile(path)) {
+ result.files.add(path);
}
- } else if (Files.isRegularFile(p)) {
- res.files.add(p);
+ } catch (IOException ex) {
+ logger.log(Level.WARNING, "パスの処理中にエラー: {0}", new Object[]{path});
}
}