@Override public void copy(Path source, Path target, CopyOption... options) throws IOException { copy(source, target, Options.getCopyOptions(options), false); }
@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 move(Path source, Path target, CopyOption... options) throws IOException { copy(source, target, Options.getMoveOptions(options), true); }
@Override public SeekableByteChannel newByteChannel( Path path, Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws IOException { checkOpen(); JimfsPath checkedPath = checkPath(path); ImmutableSet<OpenOption> opts = Options.getOptionsForChannel(options); return new JimfsFileChannel( view.getOrCreateRegularFile(checkedPath, opts), opts, fileSystemState); }
@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()); }
@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()); }
@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()); }
@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 SeekableByteChannel newByteChannel( Path path, Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws IOException { checkOpen(); JimfsPath checkedPath = checkPath(path); ImmutableSet<OpenOption> opts = Options.getOptionsForChannel(options); return new JimfsFileChannel( view.getOrCreateRegularFile(checkedPath, opts), opts, fileSystemState); }
@Override public void move(Path source, Path target, CopyOption... options) throws IOException { copy(source, target, Options.getMoveOptions(options), true); }
@Override public void copy(Path source, Path target, CopyOption... options) throws IOException { copy(source, target, Options.getCopyOptions(options), false); }
@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)); }
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 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 JimfsPath toRealPath(LinkOption... options) throws IOException { return getJimfsFileSystem() .getDefaultView() .toRealPath(this, pathService, Options.getLinkOptions(options)); }
@Override public <V extends FileAttributeView> V getFileAttributeView( Path path, Class<V> type, LinkOption... options) { checkOpen(); final JimfsPath checkedPath = checkPath(path); final ImmutableSet<LinkOption> optionsSet = Options.getLinkOptions(options); return view.getFileAttributeView( new FileLookup() { @Override public File lookup() throws IOException { checkOpen(); // per the spec, must check that the stream is open for each view operation return view .lookUpWithLock(checkedPath, optionsSet) .requireExists(checkedPath) .file(); } }, type); }
@Override public SecureDirectoryStream<Path> newDirectoryStream(Path path, LinkOption... options) throws IOException { checkOpen(); JimfsPath checkedPath = checkPath(path); // safe cast because a file system that supports SecureDirectoryStream always creates // SecureDirectoryStreams return (SecureDirectoryStream<Path>) view.newDirectoryStream( checkedPath, ALWAYS_TRUE_FILTER, Options.getLinkOptions(options), path().resolve(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)); }