// Set type of file as name of the element private void setType(Element element, Path path) { if (Files.isDirectory(path)) { element.setLocalName(FileType.DIR.getName()); return; } else if (Files.isRegularFile(path)) { element.setLocalName(FileType.FILE.getName()); return; } else if (Files.isSymbolicLink(path)) { element.setLocalName(FileType.SYMLINK.getName()); return; } else element.setLocalName(FileType.OTHER.getName()); }
@Override public FileVisitResult visitFile(Path file, BasicFileAttributes attr) { if (currentDepth >= 0) { if (!Files.isReadable(file) || Files.isSymbolicLink(file)) return FileVisitResult.CONTINUE; try { addPathToTree(file, currentDepth); return FileVisitResult.CONTINUE; } catch (IOException e) { LOG.info(e.getMessage()); return FileVisitResult.CONTINUE; } } else return FileVisitResult.SKIP_SIBLINGS; }
@Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attr) { if (currentDepth >= 0) { if (!Files.isReadable(dir) || Files.isSymbolicLink(dir)) { return FileVisitResult.SKIP_SUBTREE; } try { addPathToTree(dir, currentDepth); dir.register(watcher, ENTRY_CREATE, ENTRY_DELETE); currentDepth--; return FileVisitResult.CONTINUE; } catch (IOException e) { LOG.info(e.getMessage()); return FileVisitResult.SKIP_SUBTREE; } } else return FileVisitResult.SKIP_SIBLINGS; }