@Override public boolean isSameFile(Path path, Path path2) throws IOException { if (path.equals(path2)) { return true; } if (!(path instanceof JimfsPath && path2 instanceof JimfsPath)) { return false; } JimfsPath checkedPath = (JimfsPath) path; JimfsPath checkedPath2 = (JimfsPath) path2; FileSystemView view = getDefaultView(checkedPath); FileSystemView view2 = getDefaultView(checkedPath2); return view.isSameFile(checkedPath, view2, checkedPath2); }
private void copy(Path source, Path target, ImmutableSet<CopyOption> options, boolean move) throws IOException { JimfsPath sourcePath = checkPath(source); JimfsPath targetPath = checkPath(target); FileSystemView sourceView = getDefaultView(sourcePath); FileSystemView targetView = getDefaultView(targetPath); sourceView.copy(sourcePath, targetView, targetPath, options, move); }
@Override public void createDirectory(Path dir, FileAttribute<?>... attrs) throws IOException { JimfsPath checkedPath = checkPath(dir); FileSystemView view = getDefaultView(checkedPath); view.createDirectory(checkedPath, attrs); }
@Override public void delete(Path path) throws IOException { JimfsPath checkedPath = checkPath(path); FileSystemView view = getDefaultView(checkedPath); view.deleteFile(checkedPath, FileSystemView.DeleteMode.ANY); }
@Override public Path readSymbolicLink(Path link) throws IOException { JimfsPath checkedPath = checkPath(link); return getDefaultView(checkedPath).readSymbolicLink(checkedPath); }
@Override public DirectoryStream<Path> newDirectoryStream( Path dir, DirectoryStream.Filter<? super Path> filter) throws IOException { JimfsPath checkedPath = checkPath(dir); return getDefaultView(checkedPath) .newDirectoryStream(checkedPath, filter, Options.FOLLOW_LINKS, checkedPath); }
@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); }
@Override public void checkAccess(Path path, AccessMode... modes) throws IOException { JimfsPath checkedPath = checkPath(path); getDefaultView(checkedPath).checkAccess(checkedPath); }
@Nullable @Override public <V extends FileAttributeView> V getFileAttributeView( Path path, Class<V> type, LinkOption... options) { JimfsPath checkedPath = checkPath(path); return getDefaultView(checkedPath) .getFileAttributeView(checkedPath, type, Options.getLinkOptions(options)); }
@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 <A extends BasicFileAttributes> A readAttributes( Path path, Class<A> type, LinkOption... options) throws IOException { JimfsPath checkedPath = checkPath(path); return getDefaultView(checkedPath) .readAttributes(checkedPath, type, Options.getLinkOptions(options)); }
@Override public void setAttribute(Path path, String attribute, Object value, LinkOption... options) throws IOException { JimfsPath checkedPath = checkPath(path); getDefaultView(checkedPath) .setAttribute(checkedPath, attribute, value, Options.getLinkOptions(options)); } }
@Override public Map<String, Object> readAttributes(Path path, String attributes, LinkOption... options) throws IOException { JimfsPath checkedPath = checkPath(path); return getDefaultView(checkedPath) .readAttributes(checkedPath, attributes, Options.getLinkOptions(options)); }
@Override public boolean isHidden(Path path) throws IOException { // TODO(cgdecker): This should probably be configurable, but this seems fine for now /* * If the DOS view is supported, use the Windows isHidden method (check the dos:hidden * attribute). Otherwise, use the Unix isHidden method (just check if the file name starts with * "."). */ JimfsPath checkedPath = checkPath(path); FileSystemView view = getDefaultView(checkedPath); if (getFileStore(path).supportsFileAttributeView("dos")) { return view .readAttributes(checkedPath, DosFileAttributes.class, Options.NOFOLLOW_LINKS) .isHidden(); } return path.getNameCount() > 0 && path.getFileName().toString().startsWith("."); }
@Override public OutputStream newOutputStream(Path path, OpenOption... options) throws IOException { JimfsPath checkedPath = checkPath(path); ImmutableSet<OpenOption> opts = Options.getOptionsForOutputStream(options); FileSystemView view = getDefaultView(checkedPath); RegularFile file = view.getOrCreateRegularFile(checkedPath, opts, NO_ATTRS); return new JimfsOutputStream(file, opts.contains(APPEND), view.state()); }
private JimfsFileChannel newJimfsFileChannel( JimfsPath path, Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws IOException { ImmutableSet<OpenOption> opts = Options.getOptionsForChannel(options); FileSystemView view = getDefaultView(path); RegularFile file = view.getOrCreateRegularFile(path, opts, attrs); return new JimfsFileChannel(file, opts, view.state()); }
@Override public InputStream newInputStream(Path path, OpenOption... options) throws IOException { JimfsPath checkedPath = checkPath(path); ImmutableSet<OpenOption> opts = Options.getOptionsForInputStream(options); FileSystemView view = getDefaultView(checkedPath); RegularFile file = view.getOrCreateRegularFile(checkedPath, opts, NO_ATTRS); return new JimfsInputStream(file, view.state()); }
private void copy(Path source, Path target, ImmutableSet<CopyOption> options, boolean move) throws IOException { JimfsPath sourcePath = checkPath(source); JimfsPath targetPath = checkPath(target); FileSystemView sourceView = getDefaultView(sourcePath); FileSystemView targetView = getDefaultView(targetPath); sourceView.copy(sourcePath, targetView, targetPath, options, move); }
@Override public void createDirectory(Path dir, FileAttribute<?>... attrs) throws IOException { JimfsPath checkedPath = checkPath(dir); FileSystemView view = getDefaultView(checkedPath); view.createDirectory(checkedPath, attrs); }
private JimfsFileChannel newJimfsFileChannel( JimfsPath path, Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws IOException { ImmutableSet<OpenOption> opts = Options.getOptionsForChannel(options); FileSystemView view = getDefaultView(path); RegularFile file = view.getOrCreateRegularFile(path, opts, attrs); return new JimfsFileChannel(file, opts, view.state()); }