@Nullable private JimfsPath checkPath(Path other) { if (checkNotNull(other) instanceof JimfsPath && other.getFileSystem().equals(getFileSystem())) { return (JimfsPath) other; } return null; } }
/** * Gets the file system for the given path. */ private static JimfsFileSystem getFileSystem(Path path) { return (JimfsFileSystem) checkPath(path).getFileSystem(); }
@Override public boolean startsWith(Path other) { JimfsPath otherPath = checkPath(other); return otherPath != null && getFileSystem().equals(otherPath.getFileSystem()) && Objects.equals(root, otherPath.root) && startsWith(names, otherPath.names); }
@Override public void createSymbolicLink(Path link, Path target, FileAttribute<?>... attrs) throws IOException { JimfsPath linkPath = checkPath(link); JimfsPath targetPath = checkPath(target); checkArgument( linkPath.getFileSystem().equals(targetPath.getFileSystem()), "link and target paths must belong to the same file system instance"); FileSystemView view = getDefaultView(linkPath); view.createSymbolicLink(linkPath, targetPath, attrs); }
@Override public <V extends FileAttributeView> V getFileAttributeView(Class<V> type) { return getFileAttributeView(path().getFileSystem().getPath("."), type); }
@Override public void createLink(Path link, Path existing) throws IOException { JimfsPath linkPath = checkPath(link); JimfsPath existingPath = checkPath(existing); checkArgument( linkPath.getFileSystem().equals(existingPath.getFileSystem()), "link and existing paths must belong to the same file system instance"); FileSystemView view = getDefaultView(linkPath); view.link(linkPath, getDefaultView(existingPath), existingPath); }
@Nullable private JimfsPath checkPath(Path other) { if (checkNotNull(other) instanceof JimfsPath && other.getFileSystem().equals(getFileSystem())) { return (JimfsPath) other; } return null; } }
@Override public boolean startsWith(Path other) { JimfsPath otherPath = checkPath(other); return otherPath != null && getFileSystem().equals(otherPath.getFileSystem()) && Objects.equals(root, otherPath.root) && startsWith(names, otherPath.names); }
/** * Gets the file system for the given path. */ private static JimfsFileSystem getFileSystem(Path path) { return (JimfsFileSystem) checkPath(path).getFileSystem(); }
@Override public void createSymbolicLink(Path link, Path target, FileAttribute<?>... attrs) throws IOException { JimfsPath linkPath = checkPath(link); JimfsPath targetPath = checkPath(target); checkArgument( linkPath.getFileSystem().equals(targetPath.getFileSystem()), "link and target paths must belong to the same file system instance"); FileSystemView view = getDefaultView(linkPath); view.createSymbolicLink(linkPath, targetPath, attrs); }
@Override public <V extends FileAttributeView> V getFileAttributeView(Class<V> type) { return getFileAttributeView(path().getFileSystem().getPath("."), type); }
@Override public void createLink(Path link, Path existing) throws IOException { JimfsPath linkPath = checkPath(link); JimfsPath existingPath = checkPath(existing); checkArgument( linkPath.getFileSystem().equals(existingPath.getFileSystem()), "link and existing paths must belong to the same file system instance"); FileSystemView view = getDefaultView(linkPath); view.link(linkPath, getDefaultView(existingPath), existingPath); }