protected Path convertToAbsolute(final Path path) { if (path != null) { final RelativePathService service = property().service(RelativePathService.class); if (service == null) { if (enclosed() && path.segmentCount() > 0 && path.segment(0).equals("..")) { return null; } Path absolute = null; for (Path root : getBasePaths()) { try { final File file = root.append(path).toFile().getCanonicalFile(); absolute = new Path(file.getPath()); if (file.exists()) { break; } } catch (IOException e) { // Intentionally ignoring to continue to the next root. If none of the roots // produce a viable absolute path, a null return from this method signifies // being unable to convert the relative path. That is sufficient. } } return absolute; } else { return service.convertToAbsolute(path); } } return null; }
public FileSystemNode find(final Path path) { final int pathSegmentCount = path.segmentCount(); if (pathSegmentCount == 0) { return this; } else { final String firstSegment = path.segment(0); for (FileSystemNode child : getChildren()) { if (child.getFile().getName().equals(firstSegment)) { return child.find(path.removeFirstSegments(1)); } } return null; } }