Spec-Zone .ru
спецификации, руководства, описания, API
Please note that the specifications and other information contained herein are not final and are subject to change. The information is being made available to you solely for purpose of evaluation.

Java™ Platform
Standard Ed. 7

DRAFT ea-b118

java.nio.file.spi
Class FileSystemProvider

java.lang.Object
  extended by java.nio.file.spi.FileSystemProvider

public abstract class FileSystemProvider
extends Object

Service-provider class for file systems.

A file system provider is a concrete implementation of this class that implements the abstract methods defined by this class. A provider is identified by a URI scheme. The default provider is identified by the URI scheme "file". It creates the FileSystem that provides access to the file systems accessible to the Java virtual machine. The FileSystems class defines how file system providers are located and loaded. The default provider is typically a system-default provider but may be overridden if the system property java.nio.file.spi.DefaultFileSystemProvider is set. In that case, the provider has a one argument constructor whose formal parameter type is FileSystemProvider. All other providers have a zero argument constructor that initializes the provider.

A provider is a factory for one or more FileSystem instances. Each file system is identified by a URI where the URI's scheme matches the provider's scheme. The default file system, for example, is identified by the URI "file:///". A memory-based file system, for example, may be identified by a URI such as "memory:///?name=logfs". The newFileSystem method may be used to create a file system, and the getFileSystem method may be used to obtain a reference to an existing file system created by the provider. Where a provider is the factory for a single file system then it is provider dependent if the file system is created when the provider is initialized, or later when the newFileSystem method is invoked. In the case of the default provider, the FileSystem is created when the provider is initialized.

In addition to file systems, a provider is also a factory for FileChannel and AsynchronousFileChannel channels. The newFileChannel and AsynchronousFileChannel methods are defined to open or create files, returning a channel to access the file. These methods are invoked by static factory methods defined in the java.nio.channels package.

All of the methods in this class are safe for use by multiple concurrent threads.

Since:
1.7

Constructor Summary
Modifier Constructor and Description
protected FileSystemProvider()
          Initializes a new instance of this class.
 
Method Summary
Modifier and Type Method and Description
abstract  FileSystem getFileSystem(URI uri)
          Returns an existing FileSystem created by this provider.
abstract  Path getPath(URI uri)
          Return a Path object by converting the given URI.
abstract  String getScheme()
          Returns the URI scheme that identifies this provider.
static List<FileSystemProvider> installedProviders()
          Returns a list of the installed file system providers.
 AsynchronousFileChannel newAsynchronousFileChannel(Path path, Set<? extends OpenOption> options, ExecutorService executor, FileAttribute<?>... attrs)
          Opens or creates a file for reading and/or writing, returning an asynchronous file channel to access the file.
 FileChannel newFileChannel(Path path, Set<? extends OpenOption> options, FileAttribute<?>... attrs)
          Opens or creates a file for reading and/or writing, returning a file channel to access the file.
 FileSystem newFileSystem(FileRef file, Map<String,?> env)
          Constructs a new FileSystem to access the contents of a file as a file system.
abstract  FileSystem newFileSystem(URI uri, Map<String,?> env)
          Constructs a new FileSystem object identified by a URI.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileSystemProvider

protected FileSystemProvider()
Initializes a new instance of this class.

During construction a provider may safely access files associated with the default provider but care needs to be taken to avoid circular loading of other installed providers. If circular loading of installed providers is detected then an unspecified error is thrown.

Throws:
SecurityException - If a security manager has been installed and it denies RuntimePermission("fileSystemProvider")
Method Detail

installedProviders

public static List<FileSystemProvider> installedProviders()
Returns a list of the installed file system providers.

The first invocation of this method causes the default provider to be initialized (if not already initialized) and loads any other installed providers as described by the FileSystems class.

Returns:
An unmodifiable list of the installed file system providers. The list contains at least one element, that is the default file system provider
Throws:
ServiceConfigurationError - When an error occurs while loading a service provider

getScheme

public abstract String getScheme()
Returns the URI scheme that identifies this provider.

Returns:
The URI scheme

newFileSystem

public abstract FileSystem newFileSystem(URI uri,
                                         Map<String,?> env)
                                  throws IOException
Constructs a new FileSystem object identified by a URI. This method is invoked by the FileSystems.newFileSystem(URI,Map) method to open a new file system identified by a URI.

The uri parameter is an absolute, hierarchical URI, with a scheme equal (without regard to case) to the scheme supported by this provider. The exact form of the URI is highly provider dependent. The env parameter is a map of provider specific properties to configure the file system.

This method throws FileSystemAlreadyExistsException if the file system already exists because it was previously created by an invocation of this method. Once a file system is closed it is provider-dependent if the provider allows a new file system to be created with the same URI as a file system it previously created.

Parameters:
uri - URI reference
env - A map of provider specific properties to configure the file system; may be empty
Returns:
A new file system
Throws:
IllegalArgumentException - If the pre-conditions for the uri parameter aren't met, or the env parameter does not contain properties required by the provider, or a property value is invalid
IOException - An I/O error occurs creating the file system
SecurityException - If a security manager is installed and it denies an unspecified permission required by the file system provider implementation
FileSystemAlreadyExistsException - If the file system has already been created

getFileSystem

public abstract FileSystem getFileSystem(URI uri)
Returns an existing FileSystem created by this provider.

This method returns a reference to a FileSystem that was created by invoking the newFileSystem(URI,Map) method. File systems created the newFileSystem(FileRef,Map) method are not returned by this method. The file system is identified by its URI. Its exact form is highly provider dependent. In the case of the default provider the URI's path component is "/" and the authority, query and fragment components are undefined (Undefined components are represented by null).

Once a file system created by this provider is closed it is provider-dependent if this method returns a reference to the closed file system or throws FileSystemNotFoundException. If the provider allows a new file system to be created with the same URI as a file system it previously created then this method throws the exception if invoked after the file system is closed (and before a new instance is created by the newFileSystem method).

If a security manager is installed then a provider implementation may require to check a permission before returning a reference to an existing file system. In the case of the default file system, no permission check is required.

Parameters:
uri - URI reference
Returns:
The file system
Throws:
IllegalArgumentException - If the pre-conditions for the uri parameter aren't met
FileSystemNotFoundException - If the file system does not exist
SecurityException - If a security manager is installed and it denies an unspecified permission.

getPath

public abstract Path getPath(URI uri)
Return a Path object by converting the given URI. The resulting Path is associated with a FileSystem that already exists or is constructed automatically.

The exact form of the URI is file system provider dependent. In the case of the default provider, the URI scheme is "file" and the given URI has a non-empty path component, and undefined query, and fragment components. The resulting Path is associated with the default default FileSystem.

If a security manager is installed then a provider implementation may require to check a permission. In the case of the default file system, no permission check is required.

Parameters:
uri - The URI to convert
Throws:
IllegalArgumentException - If the URI scheme does not identify this provider or other preconditions on the uri parameter do not hold
FileSystemNotFoundException - The file system, identified by the URI, does not exist and cannot be created automatically
SecurityException - If a security manager is installed and it denies an unspecified permission.

newFileSystem

public FileSystem newFileSystem(FileRef file,
                                Map<String,?> env)
                         throws IOException
Constructs a new FileSystem to access the contents of a file as a file system.

This method is intended for specialized providers of pseudo file systems where the contents of one or more files is treated as a file system. The file parameter is a reference to an existing file and the env parameter is a map of provider specific properties to configure the file system.

If this provider does not support the creation of such file systems or if the provider does not recognize the file type of the given file then it throws UnsupportedOperationException. The default implementation of this method throws UnsupportedOperationException.

Parameters:
file - The file
env - A map of provider specific properties to configure the file system; may be empty
Returns:
A new file system
Throws:
UnsupportedOperationException - If this provider does not support access to the contents as a file system or it does not recognize the file type of the given file
IllegalArgumentException - If the env parameter does not contain properties required by the provider, or a property value is invalid
IOException - If an I/O error occurs
SecurityException - If a security manager is installed and it denies an unspecified permission.

newFileChannel

public FileChannel newFileChannel(Path path,
                                  Set<? extends OpenOption> options,
                                  FileAttribute<?>... attrs)
                           throws IOException
Opens or creates a file for reading and/or writing, returning a file channel to access the file.

This method is invoked by the FileChannel.open method to open a file channel. A provider that does not support all the features required to construct a file channel throws UnsupportedOperationException. The default provider is required to support the creation of file channels. When not overridden, the default implementation throws UnsupportedOperationException.

Parameters:
path - The path of the file to open or create
options - Options specifying how the file is opened
attrs - An optional list of file attributes to set atomically when creating the file
Returns:
A new file channel
Throws:
IllegalArgumentException - If the set contains an invalid combination of options
UnsupportedOperationException - If this provider that does not support creating file channels, or an unsupported open option or file attribute is specified
IOException - If an I/O error occurs
SecurityException - In the case of the default file system, the SecurityManager.checkRead(String) method is invoked to check read access if the file is opened for reading. The SecurityManager.checkWrite(String) method is invoked to check write access if the file is opened for writing

newAsynchronousFileChannel

public AsynchronousFileChannel newAsynchronousFileChannel(Path path,
                                                          Set<? extends OpenOption> options,
                                                          ExecutorService executor,
                                                          FileAttribute<?>... attrs)
                                                   throws IOException
Opens or creates a file for reading and/or writing, returning an asynchronous file channel to access the file.

This method is invoked by the AsynchronousFileChannel.open method to open an asynchronous file channel. A provider that does not support all the features required to construct an asynchronous file channel throws UnsupportedOperationException. The default provider is required to support the creation of asynchronous file channels. When not overridden, the default implementation of this method throws UnsupportedOperationException.

Parameters:
path - The path of the file to open or create
options - Options specifying how the file is opened
executor - The thread pool or null to associate the channel with the default thread pool
attrs - An optional list of file attributes to set atomically when creating the file
Returns:
A new asynchronous file channel
Throws:
IllegalArgumentException - If the set contains an invalid combination of options
UnsupportedOperationException - If this provider that does not support creating asynchronous file channels, or an unsupported open option or file attribute is specified
IOException - If an I/O error occurs
SecurityException - In the case of the default file system, the SecurityManager.checkRead(String) method is invoked to check read access if the file is opened for reading. The SecurityManager.checkWrite(String) method is invoked to check write access if the file is opened for writing

Java™ Platform
Standard Ed. 7

DRAFT ea-b118

Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.

Copyright © 1993, 2010, Oracle Corporation. All rights reserved.
DRAFT ea-b118

Scripting on this page tracks web page traffic, but does not change the content in any way.