@CheckForNull private File parentDir(Collection<File> dirs, File cursor) { for (File dir : dirs) { if (PathUtils.canonicalPath(dir).equals(PathUtils.canonicalPath(cursor))) { return dir; } } return null; }
@CheckForNull public String relativePath(File dir, File file) { List<String> stack = Lists.newArrayList(); String dirPath = PathUtils.canonicalPath(dir); File cursor = file; while (cursor != null) { if (dirPath.equals(PathUtils.canonicalPath(cursor))) { return Joiner.on("/").join(stack); } stack.add(0, cursor.getName()); cursor = cursor.getParentFile(); } return null; }
private DefaultInputFile(File file, String path, Map<String, String> attributes) { this.absolutePath = PathUtils.canonicalPath(file); this.path = FilenameUtils.separatorsToUnix(path); this.attributes = attributes; }