893N/A/*
3909N/A * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
893N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
893N/A *
893N/A * This code is free software; you can redistribute it and/or modify it
893N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
893N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
893N/A *
893N/A * This code is distributed in the hope that it will be useful, but WITHOUT
893N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
893N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
893N/A * version 2 for more details (a copy is included in the LICENSE file that
893N/A * accompanied this code).
893N/A *
893N/A * You should have received a copy of the GNU General Public License version
893N/A * 2 along with this work; if not, write to the Free Software Foundation,
893N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
893N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
893N/A */
893N/A
893N/Apackage java.nio.file.spi;
893N/A
893N/Aimport java.nio.file.*;
3471N/Aimport java.nio.file.attribute.*;
893N/Aimport java.nio.channels.*;
893N/Aimport java.net.URI;
3471N/Aimport java.io.InputStream;
3471N/Aimport java.io.OutputStream;
3471N/Aimport java.io.IOException;
893N/Aimport java.util.*;
893N/Aimport java.util.concurrent.ExecutorService;
893N/Aimport java.security.AccessController;
893N/Aimport java.security.PrivilegedAction;
893N/A
893N/A/**
3471N/A * Service-provider class for file systems. The methods defined by the {@link
3471N/A * java.nio.file.Files} class will typically delegate to an instance of this
3471N/A * class.
893N/A *
893N/A * <p> A file system provider is a concrete implementation of this class that
893N/A * implements the abstract methods defined by this class. A provider is
893N/A * identified by a {@code URI} {@link #getScheme() scheme}. The default provider
893N/A * is identified by the URI scheme "file". It creates the {@link FileSystem} that
893N/A * provides access to the file systems accessible to the Java virtual machine.
893N/A * The {@link FileSystems} class defines how file system providers are located
893N/A * and loaded. The default provider is typically a system-default provider but
893N/A * may be overridden if the system property {@code
893N/A * java.nio.file.spi.DefaultFileSystemProvider} is set. In that case, the
893N/A * provider has a one argument constructor whose formal parameter type is {@code
893N/A * FileSystemProvider}. All other providers have a zero argument constructor
893N/A * that initializes the provider.
893N/A *
893N/A * <p> A provider is a factory for one or more {@link FileSystem} instances. Each
893N/A * file system is identified by a {@code URI} where the URI's scheme matches
893N/A * the provider's {@link #getScheme scheme}. The default file system, for example,
893N/A * is identified by the URI {@code "file:///"}. A memory-based file system,
893N/A * for example, may be identified by a URI such as {@code "memory:///?name=logfs"}.
893N/A * The {@link #newFileSystem newFileSystem} method may be used to create a file
893N/A * system, and the {@link #getFileSystem getFileSystem} method may be used to
893N/A * obtain a reference to an existing file system created by the provider. Where
893N/A * a provider is the factory for a single file system then it is provider dependent
893N/A * if the file system is created when the provider is initialized, or later when
893N/A * the {@code newFileSystem} method is invoked. In the case of the default
893N/A * provider, the {@code FileSystem} is created when the provider is initialized.
893N/A *
893N/A * <p> All of the methods in this class are safe for use by multiple concurrent
893N/A * threads.
893N/A *
893N/A * @since 1.7
893N/A */
893N/A
893N/Apublic abstract class FileSystemProvider {
893N/A // lock using when loading providers
893N/A private static final Object lock = new Object();
893N/A
893N/A // installed providers
893N/A private static volatile List<FileSystemProvider> installedProviders;
893N/A
893N/A // used to avoid recursive loading of instaled providers
893N/A private static boolean loadingProviders = false;
893N/A
893N/A private static Void checkPermission() {
893N/A SecurityManager sm = System.getSecurityManager();
893N/A if (sm != null)
893N/A sm.checkPermission(new RuntimePermission("fileSystemProvider"));
893N/A return null;
893N/A }
893N/A private FileSystemProvider(Void ignore) { }
893N/A
893N/A /**
893N/A * Initializes a new instance of this class.
893N/A *
893N/A * <p> During construction a provider may safely access files associated
893N/A * with the default provider but care needs to be taken to avoid circular
893N/A * loading of other installed providers. If circular loading of installed
893N/A * providers is detected then an unspecified error is thrown.
893N/A *
893N/A * @throws SecurityException
893N/A * If a security manager has been installed and it denies
893N/A * {@link RuntimePermission}<tt>("fileSystemProvider")</tt>
893N/A */
893N/A protected FileSystemProvider() {
893N/A this(checkPermission());
893N/A }
893N/A
893N/A // loads all installed providers
893N/A private static List<FileSystemProvider> loadInstalledProviders() {
893N/A List<FileSystemProvider> list = new ArrayList<FileSystemProvider>();
893N/A
893N/A ServiceLoader<FileSystemProvider> sl = ServiceLoader
893N/A .load(FileSystemProvider.class, ClassLoader.getSystemClassLoader());
893N/A
893N/A // ServiceConfigurationError may be throw here
893N/A for (FileSystemProvider provider: sl) {
893N/A String scheme = provider.getScheme();
893N/A
893N/A // add to list if the provider is not "file" and isn't a duplicate
893N/A if (!scheme.equalsIgnoreCase("file")) {
893N/A boolean found = false;
893N/A for (FileSystemProvider p: list) {
893N/A if (p.getScheme().equalsIgnoreCase(scheme)) {
893N/A found = true;
893N/A break;
893N/A }
893N/A }
893N/A if (!found) {
893N/A list.add(provider);
893N/A }
893N/A }
893N/A }
893N/A return list;
893N/A }
893N/A
893N/A /**
893N/A * Returns a list of the installed file system providers.
893N/A *
893N/A * <p> The first invocation of this method causes the default provider to be
893N/A * initialized (if not already initialized) and loads any other installed
893N/A * providers as described by the {@link FileSystems} class.
893N/A *
893N/A * @return An unmodifiable list of the installed file system providers. The
893N/A * list contains at least one element, that is the default file
893N/A * system provider
893N/A *
893N/A * @throws ServiceConfigurationError
893N/A * When an error occurs while loading a service provider
893N/A */
893N/A public static List<FileSystemProvider> installedProviders() {
893N/A if (installedProviders == null) {
893N/A // ensure default provider is initialized
893N/A FileSystemProvider defaultProvider = FileSystems.getDefault().provider();
893N/A
893N/A synchronized (lock) {
893N/A if (installedProviders == null) {
893N/A if (loadingProviders) {
893N/A throw new Error("Circular loading of installed providers detected");
893N/A }
893N/A loadingProviders = true;
893N/A
893N/A List<FileSystemProvider> list = AccessController
893N/A .doPrivileged(new PrivilegedAction<List<FileSystemProvider>>() {
893N/A @Override
893N/A public List<FileSystemProvider> run() {
893N/A return loadInstalledProviders();
893N/A }});
893N/A
893N/A // insert the default provider at the start of the list
893N/A list.add(0, defaultProvider);
893N/A
893N/A installedProviders = Collections.unmodifiableList(list);
893N/A }
893N/A }
893N/A }
893N/A return installedProviders;
893N/A }
893N/A
893N/A /**
893N/A * Returns the URI scheme that identifies this provider.
893N/A *
893N/A * @return The URI scheme
893N/A */
893N/A public abstract String getScheme();
893N/A
893N/A /**
893N/A * Constructs a new {@code FileSystem} object identified by a URI. This
893N/A * method is invoked by the {@link FileSystems#newFileSystem(URI,Map)}
893N/A * method to open a new file system identified by a URI.
893N/A *
893N/A * <p> The {@code uri} parameter is an absolute, hierarchical URI, with a
893N/A * scheme equal (without regard to case) to the scheme supported by this
893N/A * provider. The exact form of the URI is highly provider dependent. The
893N/A * {@code env} parameter is a map of provider specific properties to configure
893N/A * the file system.
893N/A *
893N/A * <p> This method throws {@link FileSystemAlreadyExistsException} if the
893N/A * file system already exists because it was previously created by an
3471N/A * invocation of this method. Once a file system is {@link
3471N/A * java.nio.file.FileSystem#close closed} it is provider-dependent if the
3471N/A * provider allows a new file system to be created with the same URI as a
3471N/A * file system it previously created.
893N/A *
893N/A * @param uri
893N/A * URI reference
893N/A * @param env
893N/A * A map of provider specific properties to configure the file system;
893N/A * may be empty
893N/A *
893N/A * @return A new file system
893N/A *
893N/A * @throws IllegalArgumentException
893N/A * If the pre-conditions for the {@code uri} parameter aren't met,
893N/A * or the {@code env} parameter does not contain properties required
893N/A * by the provider, or a property value is invalid
893N/A * @throws IOException
893N/A * An I/O error occurs creating the file system
893N/A * @throws SecurityException
893N/A * If a security manager is installed and it denies an unspecified
893N/A * permission required by the file system provider implementation
893N/A * @throws FileSystemAlreadyExistsException
893N/A * If the file system has already been created
893N/A */
893N/A public abstract FileSystem newFileSystem(URI uri, Map<String,?> env)
893N/A throws IOException;
893N/A
893N/A /**
893N/A * Returns an existing {@code FileSystem} created by this provider.
893N/A *
893N/A * <p> This method returns a reference to a {@code FileSystem} that was
893N/A * created by invoking the {@link #newFileSystem(URI,Map) newFileSystem(URI,Map)}
3471N/A * method. File systems created the {@link #newFileSystem(Path,Map)
3471N/A * newFileSystem(Path,Map)} method are not returned by this method.
893N/A * The file system is identified by its {@code URI}. Its exact form
893N/A * is highly provider dependent. In the case of the default provider the URI's
893N/A * path component is {@code "/"} and the authority, query and fragment components
893N/A * are undefined (Undefined components are represented by {@code null}).
893N/A *
3471N/A * <p> Once a file system created by this provider is {@link
3471N/A * java.nio.file.FileSystem#close closed} it is provider-dependent if this
3471N/A * method returns a reference to the closed file system or throws {@link
3471N/A * FileSystemNotFoundException}. If the provider allows a new file system to
3471N/A * be created with the same URI as a file system it previously created then
3471N/A * this method throws the exception if invoked after the file system is
3471N/A * closed (and before a new instance is created by the {@link #newFileSystem
3471N/A * newFileSystem} method).
893N/A *
893N/A * <p> If a security manager is installed then a provider implementation
893N/A * may require to check a permission before returning a reference to an
893N/A * existing file system. In the case of the {@link FileSystems#getDefault
893N/A * default} file system, no permission check is required.
893N/A *
893N/A * @param uri
893N/A * URI reference
893N/A *
893N/A * @return The file system
893N/A *
893N/A * @throws IllegalArgumentException
893N/A * If the pre-conditions for the {@code uri} parameter aren't met
893N/A * @throws FileSystemNotFoundException
893N/A * If the file system does not exist
893N/A * @throws SecurityException
893N/A * If a security manager is installed and it denies an unspecified
893N/A * permission.
893N/A */
893N/A public abstract FileSystem getFileSystem(URI uri);
893N/A
893N/A /**
1319N/A * Return a {@code Path} object by converting the given {@link URI}. The
1319N/A * resulting {@code Path} is associated with a {@link FileSystem} that
1319N/A * already exists or is constructed automatically.
893N/A *
893N/A * <p> The exact form of the URI is file system provider dependent. In the
893N/A * case of the default provider, the URI scheme is {@code "file"} and the
893N/A * given URI has a non-empty path component, and undefined query, and
893N/A * fragment components. The resulting {@code Path} is associated with the
893N/A * default {@link FileSystems#getDefault default} {@code FileSystem}.
893N/A *
893N/A * <p> If a security manager is installed then a provider implementation
893N/A * may require to check a permission. In the case of the {@link
893N/A * FileSystems#getDefault default} file system, no permission check is
893N/A * required.
893N/A *
893N/A * @param uri
893N/A * The URI to convert
893N/A *
893N/A * @throws IllegalArgumentException
893N/A * If the URI scheme does not identify this provider or other
893N/A * preconditions on the uri parameter do not hold
893N/A * @throws FileSystemNotFoundException
1319N/A * The file system, identified by the URI, does not exist and
1319N/A * cannot be created automatically
893N/A * @throws SecurityException
893N/A * If a security manager is installed and it denies an unspecified
893N/A * permission.
893N/A */
893N/A public abstract Path getPath(URI uri);
893N/A
893N/A /**
893N/A * Constructs a new {@code FileSystem} to access the contents of a file as a
893N/A * file system.
893N/A *
893N/A * <p> This method is intended for specialized providers of pseudo file
893N/A * systems where the contents of one or more files is treated as a file
3471N/A * system. The {@code env} parameter is a map of provider specific properties
3471N/A * to configure the file system.
893N/A *
893N/A * <p> If this provider does not support the creation of such file systems
893N/A * or if the provider does not recognize the file type of the given file then
893N/A * it throws {@code UnsupportedOperationException}. The default implementation
893N/A * of this method throws {@code UnsupportedOperationException}.
893N/A *
3471N/A * @param path
3471N/A * The path to the file
893N/A * @param env
893N/A * A map of provider specific properties to configure the file system;
893N/A * may be empty
893N/A *
893N/A * @return A new file system
893N/A *
893N/A * @throws UnsupportedOperationException
893N/A * If this provider does not support access to the contents as a
893N/A * file system or it does not recognize the file type of the
893N/A * given file
893N/A * @throws IllegalArgumentException
893N/A * If the {@code env} parameter does not contain properties required
893N/A * by the provider, or a property value is invalid
893N/A * @throws IOException
893N/A * If an I/O error occurs
893N/A * @throws SecurityException
893N/A * If a security manager is installed and it denies an unspecified
893N/A * permission.
893N/A */
3471N/A public FileSystem newFileSystem(Path path, Map<String,?> env)
893N/A throws IOException
893N/A {
893N/A throw new UnsupportedOperationException();
893N/A }
893N/A
893N/A /**
3471N/A * Opens a file, returning an input stream to read from the file. This
3471N/A * method works in exactly the manner specified by the {@link
3471N/A * Files#newInputStream} method.
3471N/A *
3471N/A * <p> The default implementation of this method opens a channel to the file
3471N/A * as if by invoking the {@link #newByteChannel} method and constructs a
3471N/A * stream that reads bytes from the channel. This method should be overridden
3471N/A * where appropriate.
3471N/A *
3471N/A * @param path
3471N/A * the path to the file to open
3471N/A * @param options
3471N/A * options specifying how the file is opened
3471N/A *
3471N/A * @return a new input stream
893N/A *
3471N/A * @throws IllegalArgumentException
3471N/A * if an invalid combination of options is specified
3471N/A * @throws UnsupportedOperationException
3471N/A * if an unsupported option is specified
3471N/A * @throws IOException
3471N/A * if an I/O error occurs
3471N/A * @throws SecurityException
3471N/A * In the case of the default provider, and a security manager is
3471N/A * installed, the {@link SecurityManager#checkRead(String) checkRead}
3471N/A * method is invoked to check read access to the file.
3471N/A */
3471N/A public InputStream newInputStream(Path path, OpenOption... options)
3471N/A throws IOException
3471N/A {
3471N/A if (options.length > 0) {
3471N/A for (OpenOption opt: options) {
3471N/A if (opt != StandardOpenOption.READ)
3471N/A throw new UnsupportedOperationException("'" + opt + "' not allowed");
3471N/A }
3471N/A }
3471N/A return Channels.newInputStream(Files.newByteChannel(path));
3471N/A }
3471N/A
3471N/A /**
3471N/A * Opens or creates a file, returning an output stream that may be used to
3471N/A * write bytes to the file. This method works in exactly the manner
3471N/A * specified by the {@link Files#newOutputStream} method.
3471N/A *
3471N/A * <p> The default implementation of this method opens a channel to the file
3471N/A * as if by invoking the {@link #newByteChannel} method and constructs a
3471N/A * stream that writes bytes to the channel. This method should be overridden
3471N/A * where appropriate.
893N/A *
893N/A * @param path
3471N/A * the path to the file to open or create
893N/A * @param options
3471N/A * options specifying how the file is opened
3471N/A *
3471N/A * @return a new output stream
3471N/A *
3471N/A * @throws IllegalArgumentException
3471N/A * if {@code options} contains an invalid combination of options
3471N/A * @throws UnsupportedOperationException
3471N/A * if an unsupported option is specified
3471N/A * @throws IOException
3471N/A * if an I/O error occurs
3471N/A * @throws SecurityException
3471N/A * In the case of the default provider, and a security manager is
3471N/A * installed, the {@link SecurityManager#checkWrite(String) checkWrite}
3471N/A * method is invoked to check write access to the file. The {@link
3471N/A * SecurityManager#checkDelete(String) checkDelete} method is
3471N/A * invoked to check delete access if the file is opened with the
3471N/A * {@code DELETE_ON_CLOSE} option.
3471N/A */
3471N/A public OutputStream newOutputStream(Path path, OpenOption... options)
3471N/A throws IOException
3471N/A {
3471N/A int len = options.length;
3471N/A Set<OpenOption> opts = new HashSet<OpenOption>(len + 3);
3471N/A if (len == 0) {
3471N/A opts.add(StandardOpenOption.CREATE);
3471N/A opts.add(StandardOpenOption.TRUNCATE_EXISTING);
3471N/A } else {
3471N/A for (OpenOption opt: options) {
3471N/A if (opt == StandardOpenOption.READ)
3471N/A throw new IllegalArgumentException("READ not allowed");
3471N/A opts.add(opt);
3471N/A }
3471N/A }
3471N/A opts.add(StandardOpenOption.WRITE);
3471N/A return Channels.newOutputStream(newByteChannel(path, opts));
3471N/A }
3471N/A
3471N/A /**
3471N/A * Opens or creates a file for reading and/or writing, returning a file
3471N/A * channel to access the file. This method works in exactly the manner
3471N/A * specified by the {@link FileChannel#open(Path,Set,FileAttribute[])
3471N/A * FileChannel.open} method. A provider that does not support all the
3471N/A * features required to construct a file channel throws {@code
3471N/A * UnsupportedOperationException}. The default provider is required to
3471N/A * support the creation of file channels. When not overridden, the default
3471N/A * implementation throws {@code UnsupportedOperationException}.
3471N/A *
3471N/A * @param path
3471N/A * the path of the file to open or create
3471N/A * @param options
3471N/A * options specifying how the file is opened
893N/A * @param attrs
3471N/A * an optional list of file attributes to set atomically when
893N/A * creating the file
893N/A *
3471N/A * @return a new file channel
893N/A *
893N/A * @throws IllegalArgumentException
893N/A * If the set contains an invalid combination of options
893N/A * @throws UnsupportedOperationException
893N/A * If this provider that does not support creating file channels,
893N/A * or an unsupported open option or file attribute is specified
893N/A * @throws IOException
893N/A * If an I/O error occurs
893N/A * @throws SecurityException
893N/A * In the case of the default file system, the {@link
893N/A * SecurityManager#checkRead(String)} method is invoked to check
893N/A * read access if the file is opened for reading. The {@link
893N/A * SecurityManager#checkWrite(String)} method is invoked to check
893N/A * write access if the file is opened for writing
893N/A */
893N/A public FileChannel newFileChannel(Path path,
893N/A Set<? extends OpenOption> options,
893N/A FileAttribute<?>... attrs)
893N/A throws IOException
893N/A {
893N/A throw new UnsupportedOperationException();
893N/A }
893N/A
893N/A /**
893N/A * Opens or creates a file for reading and/or writing, returning an
3471N/A * asynchronous file channel to access the file. This method works in
3471N/A * exactly the manner specified by the {@link
893N/A * AsynchronousFileChannel#open(Path,Set,ExecutorService,FileAttribute[])
3471N/A * AsynchronousFileChannel.open} method.
893N/A * A provider that does not support all the features required to construct
893N/A * an asynchronous file channel throws {@code UnsupportedOperationException}.
893N/A * The default provider is required to support the creation of asynchronous
893N/A * file channels. When not overridden, the default implementation of this
893N/A * method throws {@code UnsupportedOperationException}.
893N/A *
893N/A * @param path
3471N/A * the path of the file to open or create
893N/A * @param options
3471N/A * options specifying how the file is opened
893N/A * @param executor
3471N/A * the thread pool or {@code null} to associate the channel with
893N/A * the default thread pool
893N/A * @param attrs
3471N/A * an optional list of file attributes to set atomically when
893N/A * creating the file
893N/A *
3471N/A * @return a new asynchronous file channel
893N/A *
893N/A * @throws IllegalArgumentException
893N/A * If the set contains an invalid combination of options
893N/A * @throws UnsupportedOperationException
893N/A * If this provider that does not support creating asynchronous file
893N/A * channels, or an unsupported open option or file attribute is
893N/A * specified
893N/A * @throws IOException
893N/A * If an I/O error occurs
893N/A * @throws SecurityException
893N/A * In the case of the default file system, the {@link
893N/A * SecurityManager#checkRead(String)} method is invoked to check
893N/A * read access if the file is opened for reading. The {@link
893N/A * SecurityManager#checkWrite(String)} method is invoked to check
893N/A * write access if the file is opened for writing
893N/A */
893N/A public AsynchronousFileChannel newAsynchronousFileChannel(Path path,
893N/A Set<? extends OpenOption> options,
893N/A ExecutorService executor,
893N/A FileAttribute<?>... attrs)
893N/A throws IOException
893N/A {
893N/A throw new UnsupportedOperationException();
893N/A }
3471N/A
3471N/A /**
3471N/A * Opens or creates a file, returning a seekable byte channel to access the
3471N/A * file. This method works in exactly the manner specified by the {@link
3471N/A * Files#newByteChannel(Path,Set,FileAttribute[])} method.
3471N/A *
3471N/A * @param path
3471N/A * the path to the file to open or create
3471N/A * @param options
3471N/A * options specifying how the file is opened
3471N/A * @param attrs
3471N/A * an optional list of file attributes to set atomically when
3471N/A * creating the file
3471N/A *
3471N/A * @return a new seekable byte channel
3471N/A *
3471N/A * @throws IllegalArgumentException
3471N/A * if the set contains an invalid combination of options
3471N/A * @throws UnsupportedOperationException
3471N/A * if an unsupported open option is specified or the array contains
3471N/A * attributes that cannot be set atomically when creating the file
3471N/A * @throws FileAlreadyExistsException
3471N/A * if a file of that name already exists and the {@link
3471N/A * StandardOpenOption#CREATE_NEW CREATE_NEW} option is specified
3471N/A * <i>(optional specific exception)</i>
3471N/A * @throws IOException
3471N/A * if an I/O error occurs
3471N/A * @throws SecurityException
3471N/A * In the case of the default provider, and a security manager is
3471N/A * installed, the {@link SecurityManager#checkRead(String) checkRead}
3471N/A * method is invoked to check read access to the path if the file is
3471N/A * opened for reading. The {@link SecurityManager#checkWrite(String)
3471N/A * checkWrite} method is invoked to check write access to the path
3471N/A * if the file is opened for writing. The {@link
3471N/A * SecurityManager#checkDelete(String) checkDelete} method is
3471N/A * invoked to check delete access if the file is opened with the
3471N/A * {@code DELETE_ON_CLOSE} option.
3471N/A */
3471N/A public abstract SeekableByteChannel newByteChannel(Path path,
3471N/A Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws IOException;
3471N/A
3471N/A /**
3471N/A * Opens a directory, returning a {@code DirectoryStream} to iterate over
3471N/A * the entries in the directory. This method works in exactly the manner
3471N/A * specified by the {@link
3471N/A * Files#newDirectoryStream(java.nio.file.Path, java.nio.file.DirectoryStream.Filter)}
3471N/A * method.
3471N/A *
3471N/A * @param dir
3471N/A * the path to the directory
3471N/A * @param filter
3471N/A * the directory stream filter
3471N/A *
3471N/A * @return a new and open {@code DirectoryStream} object
3471N/A *
3471N/A * @throws NotDirectoryException
3471N/A * if the file could not otherwise be opened because it is not
3471N/A * a directory <i>(optional specific exception)</i>
3471N/A * @throws IOException
3471N/A * if an I/O error occurs
3471N/A * @throws SecurityException
3471N/A * In the case of the default provider, and a security manager is
3471N/A * installed, the {@link SecurityManager#checkRead(String) checkRead}
3471N/A * method is invoked to check read access to the directory.
3471N/A */
3471N/A public abstract DirectoryStream<Path> newDirectoryStream(Path dir,
3471N/A DirectoryStream.Filter<? super Path> filter) throws IOException;
3471N/A
3471N/A /**
3471N/A * Creates a new directory. This method works in exactly the manner
3471N/A * specified by the {@link Files#createDirectory} method.
3471N/A *
3471N/A * @param dir
3471N/A * the directory to create
3471N/A * @param attrs
3471N/A * an optional list of file attributes to set atomically when
3471N/A * creating the directory
3471N/A *
3471N/A * @throws UnsupportedOperationException
3471N/A * if the array contains an attribute that cannot be set atomically
3471N/A * when creating the directory
3471N/A * @throws FileAlreadyExistsException
3471N/A * if a directory could not otherwise be created because a file of
3471N/A * that name already exists <i>(optional specific exception)</i>
3471N/A * @throws IOException
3471N/A * if an I/O error occurs or the parent directory does not exist
3471N/A * @throws SecurityException
3471N/A * In the case of the default provider, and a security manager is
3471N/A * installed, the {@link SecurityManager#checkWrite(String) checkWrite}
3471N/A * method is invoked to check write access to the new directory.
3471N/A */
3471N/A public abstract void createDirectory(Path dir, FileAttribute<?>... attrs)
3471N/A throws IOException;
3471N/A
3471N/A /**
3471N/A * Creates a symbolic link to a target. This method works in exactly the
3471N/A * manner specified by the {@link Files#createSymbolicLink} method.
3471N/A *
3471N/A * <p> The default implementation of this method throws {@code
3471N/A * UnsupportedOperationException}.
3471N/A *
3471N/A * @param link
3471N/A * the path of the symbolic link to create
3471N/A * @param target
3471N/A * the target of the symbolic link
3471N/A * @param attrs
3471N/A * the array of attributes to set atomically when creating the
3471N/A * symbolic link
3471N/A *
3471N/A * @throws UnsupportedOperationException
3471N/A * if the implementation does not support symbolic links or the
3471N/A * array contains an attribute that cannot be set atomically when
3471N/A * creating the symbolic link
3471N/A * @throws FileAlreadyExistsException
3471N/A * if a file with the name already exists <i>(optional specific
3471N/A * exception)</i>
3471N/A * @throws IOException
3471N/A * if an I/O error occurs
3471N/A * @throws SecurityException
3471N/A * In the case of the default provider, and a security manager
3471N/A * is installed, it denies {@link LinkPermission}<tt>("symbolic")</tt>
3471N/A * or its {@link SecurityManager#checkWrite(String) checkWrite}
3471N/A * method denies write access to the path of the symbolic link.
3471N/A */
3471N/A public void createSymbolicLink(Path link, Path target, FileAttribute<?>... attrs)
3471N/A throws IOException
3471N/A {
3471N/A throw new UnsupportedOperationException();
3471N/A }
3471N/A
3471N/A /**
3471N/A * Creates a new link (directory entry) for an existing file. This method
3471N/A * works in exactly the manner specified by the {@link Files#createLink}
3471N/A * method.
3471N/A *
3471N/A * <p> The default implementation of this method throws {@code
3471N/A * UnsupportedOperationException}.
3471N/A *
3471N/A * @param link
3471N/A * the link (directory entry) to create
3471N/A * @param existing
3471N/A * a path to an existing file
3471N/A *
3471N/A * @throws UnsupportedOperationException
3471N/A * if the implementation does not support adding an existing file
3471N/A * to a directory
3471N/A * @throws FileAlreadyExistsException
3471N/A * if the entry could not otherwise be created because a file of
3471N/A * that name already exists <i>(optional specific exception)</i>
3471N/A * @throws IOException
3471N/A * if an I/O error occurs
3471N/A * @throws SecurityException
3471N/A * In the case of the default provider, and a security manager
3471N/A * is installed, it denies {@link LinkPermission}<tt>("hard")</tt>
3471N/A * or its {@link SecurityManager#checkWrite(String) checkWrite}
3471N/A * method denies write access to either the link or the
3471N/A * existing file.
3471N/A */
3471N/A public void createLink(Path link, Path existing) throws IOException {
3471N/A throw new UnsupportedOperationException();
3471N/A }
3471N/A
3471N/A /**
3471N/A * Deletes a file. This method works in exactly the manner specified by the
3471N/A * {@link Files#delete} method.
3471N/A *
3471N/A * @param path
3471N/A * the path to the file to delete
3471N/A *
3471N/A * @throws NoSuchFileException
3471N/A * if the file does not exist <i>(optional specific exception)</i>
3471N/A * @throws DirectoryNotEmptyException
3471N/A * if the file is a directory and could not otherwise be deleted
3471N/A * because the directory is not empty <i>(optional specific
3471N/A * exception)</i>
3471N/A * @throws IOException
3471N/A * if an I/O error occurs
3471N/A * @throws SecurityException
3471N/A * In the case of the default provider, and a security manager is
3471N/A * installed, the {@link SecurityManager#checkDelete(String)} method
3471N/A * is invoked to check delete access to the file
3471N/A */
3471N/A public abstract void delete(Path path) throws IOException;
3471N/A
3471N/A /**
3471N/A * Deletes a file if it exists. This method works in exactly the manner
3471N/A * specified by the {@link Files#deleteIfExists} method.
3471N/A *
3471N/A * <p> The default implementation of this method simply invokes {@link
3471N/A * #delete} ignoring the {@code NoSuchFileException} when the file does not
3471N/A * exist. It may be overridden where appropriate.
3471N/A *
3471N/A * @param path
3471N/A * the path to the file to delete
3471N/A *
3471N/A * @return {@code true} if the file was deleted by this method; {@code
3471N/A * false} if the file could not be deleted because it did not
3471N/A * exist
3471N/A *
3471N/A * @throws DirectoryNotEmptyException
3471N/A * if the file is a directory and could not otherwise be deleted
3471N/A * because the directory is not empty <i>(optional specific
3471N/A * exception)</i>
3471N/A * @throws IOException
3471N/A * if an I/O error occurs
3471N/A * @throws SecurityException
3471N/A * In the case of the default provider, and a security manager is
3471N/A * installed, the {@link SecurityManager#checkDelete(String)} method
3471N/A * is invoked to check delete access to the file
3471N/A */
3471N/A public boolean deleteIfExists(Path path) throws IOException {
3471N/A try {
3471N/A delete(path);
3471N/A return true;
3471N/A } catch (NoSuchFileException ignore) {
3471N/A return false;
3471N/A }
3471N/A }
3471N/A
3471N/A /**
3471N/A * Reads the target of a symbolic link. This method works in exactly the
3471N/A * manner specified by the {@link Files#readSymbolicLink} method.
3471N/A *
3471N/A * <p> The default implementation of this method throws {@code
3471N/A * UnsupportedOperationException}.
3471N/A *
3471N/A * @param link
3471N/A * the path to the symbolic link
3471N/A *
3471N/A * @throws UnsupportedOperationException
3471N/A * if the implementation does not support symbolic links
3471N/A * @throws NotLinkException
3471N/A * if the target could otherwise not be read because the file
3471N/A * is not a symbolic link <i>(optional specific exception)</i>
3471N/A * @throws IOException
3471N/A * if an I/O error occurs
3471N/A * @throws SecurityException
3471N/A * In the case of the default provider, and a security manager
3471N/A * is installed, it checks that {@code FilePermission} has been
3471N/A * granted with the "{@code readlink}" action to read the link.
3471N/A */
3471N/A public Path readSymbolicLink(Path link) throws IOException {
3471N/A throw new UnsupportedOperationException();
3471N/A }
3471N/A
3471N/A /**
3471N/A * Copy a file to a target file. This method works in exactly the manner
3471N/A * specified by the {@link Files#copy(Path,Path,CopyOption[])} method
3471N/A * except that both the source and target paths must be associated with
3471N/A * this provider.
3471N/A *
3471N/A * @param source
3471N/A * the path to the file to copy
3471N/A * @param target
3471N/A * the path to the target file
3471N/A * @param options
3471N/A * options specifying how the copy should be done
3471N/A *
3471N/A * @throws UnsupportedOperationException
3471N/A * if the array contains a copy option that is not supported
3471N/A * @throws FileAlreadyExistsException
3471N/A * if the target file exists but cannot be replaced because the
3471N/A * {@code REPLACE_EXISTING} option is not specified <i>(optional
3471N/A * specific exception)</i>
3471N/A * @throws DirectoryNotEmptyException
3471N/A * the {@code REPLACE_EXISTING} option is specified but the file
3471N/A * cannot be replaced because it is a non-empty directory
3471N/A * <i>(optional specific exception)</i>
3471N/A * @throws IOException
3471N/A * if an I/O error occurs
3471N/A * @throws SecurityException
3471N/A * In the case of the default provider, and a security manager is
3471N/A * installed, the {@link SecurityManager#checkRead(String) checkRead}
3471N/A * method is invoked to check read access to the source file, the
3471N/A * {@link SecurityManager#checkWrite(String) checkWrite} is invoked
3471N/A * to check write access to the target file. If a symbolic link is
3471N/A * copied the security manager is invoked to check {@link
3471N/A * LinkPermission}{@code ("symbolic")}.
3471N/A */
3471N/A public abstract void copy(Path source, Path target, CopyOption... options)
3471N/A throws IOException;
3471N/A
3471N/A /**
3471N/A * Move or rename a file to a target file. This method works in exactly the
3471N/A * manner specified by the {@link Files#move} method except that both the
3471N/A * source and target paths must be associated with this provider.
3471N/A *
3471N/A * @param source
3471N/A * the path to the file to move
3471N/A * @param target
3471N/A * the path to the target file
3471N/A * @param options
3471N/A * options specifying how the move should be done
3471N/A *
3471N/A * @throws UnsupportedOperationException
3471N/A * if the array contains a copy option that is not supported
3471N/A * @throws FileAlreadyExistsException
3471N/A * if the target file exists but cannot be replaced because the
3471N/A * {@code REPLACE_EXISTING} option is not specified <i>(optional
3471N/A * specific exception)</i>
3471N/A * @throws DirectoryNotEmptyException
3471N/A * the {@code REPLACE_EXISTING} option is specified but the file
3471N/A * cannot be replaced because it is a non-empty directory
3471N/A * <i>(optional specific exception)</i>
3471N/A * @throws AtomicMoveNotSupportedException
3471N/A * if the options array contains the {@code ATOMIC_MOVE} option but
3471N/A * the file cannot be moved as an atomic file system operation.
3471N/A * @throws IOException
3471N/A * if an I/O error occurs
3471N/A * @throws SecurityException
3471N/A * In the case of the default provider, and a security manager is
3471N/A * installed, the {@link SecurityManager#checkWrite(String) checkWrite}
3471N/A * method is invoked to check write access to both the source and
3471N/A * target file.
3471N/A */
3471N/A public abstract void move(Path source, Path target, CopyOption... options)
3471N/A throws IOException;
3471N/A
3471N/A /**
3471N/A * Tests if two paths locate the same file. This method works in exactly the
3471N/A * manner specified by the {@link Files#isSameFile} method.
3471N/A *
3471N/A * @param path
3471N/A * one path to the file
3471N/A * @param path2
3471N/A * the other path
3471N/A *
3471N/A * @return {@code true} if, and only if, the two paths locate the same file
3471N/A *
3471N/A * @throws IOException
3471N/A * if an I/O error occurs
3471N/A * @throws SecurityException
3471N/A * In the case of the default provider, and a security manager is
3471N/A * installed, the {@link SecurityManager#checkRead(String) checkRead}
3471N/A * method is invoked to check read access to both files.
3471N/A */
3471N/A public abstract boolean isSameFile(Path path, Path path2)
3471N/A throws IOException;
3471N/A
3471N/A /**
3471N/A * Tells whether or not a file is considered <em>hidden</em>. This method
3471N/A * works in exactly the manner specified by the {@link Files#isHidden}
3471N/A * method.
3471N/A *
3471N/A * <p> This method is invoked by the {@link Files#isHidden isHidden} method.
3471N/A *
3471N/A * @param path
3471N/A * the path to the file to test
3471N/A *
3471N/A * @return {@code true} if the file is considered hidden
3471N/A *
3471N/A * @throws IOException
3471N/A * if an I/O error occurs
3471N/A * @throws SecurityException
3471N/A * In the case of the default provider, and a security manager is
3471N/A * installed, the {@link SecurityManager#checkRead(String) checkRead}
3471N/A * method is invoked to check read access to the file.
3471N/A */
3471N/A public abstract boolean isHidden(Path path) throws IOException;
3471N/A
3471N/A /**
3471N/A * Returns the {@link FileStore} representing the file store where a file
3471N/A * is located. This method works in exactly the manner specified by the
3471N/A * {@link Files#getFileStore} method.
3471N/A *
3471N/A * @param path
3471N/A * the path to the file
3471N/A *
3471N/A * @return the file store where the file is stored
3471N/A *
3471N/A * @throws IOException
3471N/A * if an I/O error occurs
3471N/A * @throws SecurityException
3471N/A * In the case of the default provider, and a security manager is
3471N/A * installed, the {@link SecurityManager#checkRead(String) checkRead}
3471N/A * method is invoked to check read access to the file, and in
3471N/A * addition it checks {@link RuntimePermission}<tt>
3471N/A * ("getFileStoreAttributes")</tt>
3471N/A */
3471N/A public abstract FileStore getFileStore(Path path) throws IOException;
3471N/A
3471N/A /**
3471N/A * Checks the existence, and optionally the accessibility, of a file.
3471N/A *
3471N/A * <p> This method may be used by the {@link Files#isReadable isReadable},
3471N/A * {@link Files#isWritable isWritable} and {@link Files#isExecutable
3471N/A * isExecutable} methods to check the accessibility of a file.
3471N/A *
3471N/A * <p> This method checks the existence of a file and that this Java virtual
3471N/A * machine has appropriate privileges that would allow it access the file
3471N/A * according to all of access modes specified in the {@code modes} parameter
3471N/A * as follows:
3471N/A *
3471N/A * <table border=1 cellpadding=5 summary="">
3471N/A * <tr> <th>Value</th> <th>Description</th> </tr>
3471N/A * <tr>
3471N/A * <td> {@link AccessMode#READ READ} </td>
3471N/A * <td> Checks that the file exists and that the Java virtual machine has
3471N/A * permission to read the file. </td>
3471N/A * </tr>
3471N/A * <tr>
3471N/A * <td> {@link AccessMode#WRITE WRITE} </td>
3471N/A * <td> Checks that the file exists and that the Java virtual machine has
3471N/A * permission to write to the file, </td>
3471N/A * </tr>
3471N/A * <tr>
3471N/A * <td> {@link AccessMode#EXECUTE EXECUTE} </td>
3471N/A * <td> Checks that the file exists and that the Java virtual machine has
3471N/A * permission to {@link Runtime#exec execute} the file. The semantics
3471N/A * may differ when checking access to a directory. For example, on UNIX
3471N/A * systems, checking for {@code EXECUTE} access checks that the Java
3471N/A * virtual machine has permission to search the directory in order to
3471N/A * access file or subdirectories. </td>
3471N/A * </tr>
3471N/A * </table>
3471N/A *
3471N/A * <p> If the {@code modes} parameter is of length zero, then the existence
3471N/A * of the file is checked.
3471N/A *
3471N/A * <p> This method follows symbolic links if the file referenced by this
3471N/A * object is a symbolic link. Depending on the implementation, this method
3471N/A * may require to read file permissions, access control lists, or other
3471N/A * file attributes in order to check the effective access to the file. To
3471N/A * determine the effective access to a file may require access to several
3471N/A * attributes and so in some implementations this method may not be atomic
3471N/A * with respect to other file system operations.
3471N/A *
3471N/A * @param path
3471N/A * the path to the file to check
3471N/A * @param modes
3471N/A * The access modes to check; may have zero elements
3471N/A *
3471N/A * @throws UnsupportedOperationException
3471N/A * an implementation is required to support checking for
3471N/A * {@code READ}, {@code WRITE}, and {@code EXECUTE} access. This
3471N/A * exception is specified to allow for the {@code Access} enum to
3471N/A * be extended in future releases.
3471N/A * @throws NoSuchFileException
3471N/A * if a file does not exist <i>(optional specific exception)</i>
3471N/A * @throws AccessDeniedException
3471N/A * the requested access would be denied or the access cannot be
3471N/A * determined because the Java virtual machine has insufficient
3471N/A * privileges or other reasons. <i>(optional specific exception)</i>
3471N/A * @throws IOException
3471N/A * if an I/O error occurs
3471N/A * @throws SecurityException
3471N/A * In the case of the default provider, and a security manager is
3471N/A * installed, the {@link SecurityManager#checkRead(String) checkRead}
3471N/A * is invoked when checking read access to the file or only the
3471N/A * existence of the file, the {@link SecurityManager#checkWrite(String)
3471N/A * checkWrite} is invoked when checking write access to the file,
3471N/A * and {@link SecurityManager#checkExec(String) checkExec} is invoked
3471N/A * when checking execute access.
3471N/A */
3471N/A public abstract void checkAccess(Path path, AccessMode... modes)
3471N/A throws IOException;
3471N/A
3471N/A /**
3471N/A * Returns a file attribute view of a given type. This method works in
3471N/A * exactly the manner specified by the {@link Files#getFileAttributeView}
3471N/A * method.
3471N/A *
3471N/A * @param path
3471N/A * the path to the file
3471N/A * @param type
3471N/A * the {@code Class} object corresponding to the file attribute view
3471N/A * @param options
3471N/A * options indicating how symbolic links are handled
3471N/A *
3471N/A * @return a file attribute view of the specified type, or {@code null} if
3471N/A * the attribute view type is not available
3471N/A */
3471N/A public abstract <V extends FileAttributeView> V
3471N/A getFileAttributeView(Path path, Class<V> type, LinkOption... options);
3471N/A
3471N/A /**
3471N/A * Reads a file's attributes as a bulk operation. This method works in
3471N/A * exactly the manner specified by the {@link
3471N/A * Files#readAttributes(Path,Class,LinkOption[])} method.
3471N/A *
3471N/A * @param path
3471N/A * the path to the file
3471N/A * @param type
3471N/A * the {@code Class} of the file attributes required
3471N/A * to read
3471N/A * @param options
3471N/A * options indicating how symbolic links are handled
3471N/A *
3471N/A * @return the file attributes
3471N/A *
3471N/A * @throws UnsupportedOperationException
3471N/A * if an attributes of the given type are not supported
3471N/A * @throws IOException
3471N/A * if an I/O error occurs
3471N/A * @throws SecurityException
3471N/A * In the case of the default provider, a security manager is
3471N/A * installed, its {@link SecurityManager#checkRead(String) checkRead}
3471N/A * method is invoked to check read access to the file
3471N/A */
3471N/A public abstract <A extends BasicFileAttributes> A
3471N/A readAttributes(Path path, Class<A> type, LinkOption... options) throws IOException;
3471N/A
3471N/A /**
3471N/A * Reads a set of file attributes as a bulk operation. This method works in
3471N/A * exactly the manner specified by the {@link
3471N/A * Files#readAttributes(Path,String,LinkOption[])} method.
3471N/A *
3471N/A * @param path
3471N/A * the path to the file
3471N/A * @param attributes
3471N/A * the attributes to read
3471N/A * @param options
3471N/A * options indicating how symbolic links are handled
3471N/A *
3471N/A * @return a map of the attributes returned; may be empty. The map's keys
3471N/A * are the attribute names, its values are the attribute values
3471N/A *
3779N/A * @throws UnsupportedOperationException
3779N/A * if the attribute view is not available
3779N/A * @throws IllegalArgumentException
3779N/A * if no attributes are specified or an unrecognized attributes is
3779N/A * specified
3471N/A * @throws IOException
3471N/A * If an I/O error occurs
3471N/A * @throws SecurityException
3471N/A * In the case of the default provider, and a security manager is
3471N/A * installed, its {@link SecurityManager#checkRead(String) checkRead}
3471N/A * method denies read access to the file. If this method is invoked
3471N/A * to read security sensitive attributes then the security manager
3471N/A * may be invoke to check for additional permissions.
3471N/A */
3471N/A public abstract Map<String,Object> readAttributes(Path path, String attributes,
3471N/A LinkOption... options)
3471N/A throws IOException;
3471N/A
3471N/A /**
3471N/A * Sets the value of a file attribute. This method works in exactly the
3471N/A * manner specified by the {@link Files#setAttribute} method.
3471N/A *
3471N/A * @param path
3471N/A * the path to the file
3471N/A * @param attribute
3471N/A * the attribute to set
3471N/A * @param value
3471N/A * the attribute value
3471N/A * @param options
3471N/A * options indicating how symbolic links are handled
3471N/A *
3471N/A * @throws UnsupportedOperationException
3779N/A * if the attribute view is not available
3471N/A * @throws IllegalArgumentException
3779N/A * if the attribute name is not specified, or is not recognized, or
3779N/A * the attribute value is of the correct type but has an
3471N/A * inappropriate value
3471N/A * @throws ClassCastException
3471N/A * If the attribute value is not of the expected type or is a
3471N/A * collection containing elements that are not of the expected
3471N/A * type
3471N/A * @throws IOException
3471N/A * If an I/O error occurs
3471N/A * @throws SecurityException
3471N/A * In the case of the default provider, and a security manager is
3471N/A * installed, its {@link SecurityManager#checkWrite(String) checkWrite}
3471N/A * method denies write access to the file. If this method is invoked
3471N/A * to set security sensitive attributes then the security manager
3471N/A * may be invoked to check for additional permissions.
3471N/A */
3471N/A public abstract void setAttribute(Path path, String attribute,
3471N/A Object value, LinkOption... options)
3471N/A throws IOException;
893N/A}