Summary
Update java.nio.file.FileSystems with new factory methods to make it easier for users to work with file system providers that treat the contents of a file as a file system.
Problem
Currently the API doesn't make it easy to provide configuration settings when opening a file as a file system. Users are forced to use the newFileSystem method that takes a URI to the zip or JAR file as these are the only methods that also take a Map with configuration settings (such as the "create" property to create a zip file).
Solution
Add the following methods to java.nio.file.FileSystems:
newFileSystem(Path)
newFileSystem(Path, Map<String, ?>)
newFileSystem(Path, Map<String, ?>, ClassLoader)
Specification
/**
* Constructs a new {@code FileSystem} to access the contents of a file as a
* file system.
*
* <p> This method makes use of specialized providers that create pseudo file
* systems where the contents of one or more files is treated as a file
* system.
*
* <p> This method first attempts to locate an installed provider in exactly
* the same manner as the {@link #newFileSystem(Path,Map,ClassLoader)
* newFileSystem(Path, Map, ClassLoader)}. If found, the provider's
* {@link FileSystemProvider#newFileSystem(Path, Map) newFileSystem(Path, Map)}
* method is invoked to construct the new file system.
*
* @param path
* the path to the file
* @param env
* a map of provider specific properties to configure the file system;
* may be empty
*
* @return a new file system
*
* @throws ProviderNotFoundException
* if a provider supporting this file type cannot be located
* @throws ServiceConfigurationError
* when an error occurs while loading a service provider
* @throws IOException
* if an I/O error occurs
* @throws SecurityException
* if a security manager is installed and it denies an unspecified
* permission
*
* @since 13
*/
public static FileSystem newFileSystem(Path path, Map<String,?> env)
throws IOException
/**
* Constructs a new {@code FileSystem} to access the contents of a file as a
* file system.
*
* <p> This method makes use of specialized providers that create pseudo file
* systems where the contents of one or more files is treated as a file
* system.
*
* <p> This method first attempts to locate an installed provider in exactly
* the same manner as the {@link #newFileSystem(Path,Map,ClassLoader)
* newFileSystem(Path, Map, ClassLoader)}. If found, the provider's
* {@link FileSystemProvider#newFileSystem(Path, Map) newFileSystem(Path, Map)}
* method is invoked with an empty map to construct the new file system.
*
* @param path
* the path to the file
*
* @return a new file system
*
* @throws ProviderNotFoundException
* if a provider supporting this file type cannot be located
* @throws ServiceConfigurationError
* when an error occurs while loading a service provider
* @throws IOException
* if an I/O error occurs
* @throws SecurityException
* if a security manager is installed and it denies an unspecified
* permission
*
* @since 13
*/
public static FileSystem newFileSystem(Path path)
throws IOException
/**
* Constructs a new {@code FileSystem} to access the contents of a file as a
* file system.
*
* <p> This method makes use of specialized providers that create pseudo file
* systems where the contents of one or more files is treated as a file
* system.
*
* <p> This method iterates over the {@link FileSystemProvider#installedProviders()
* installed} providers. It invokes, in turn, each provider's {@link
* FileSystemProvider#newFileSystem(Path,Map) newFileSystem(Path,Map)}
* method. If a provider returns a file system then the iteration
* terminates and the file system is returned.
* If none of the installed providers return a {@code FileSystem} then
* an attempt is made to locate the provider using the given class loader.
* If a provider returns a file
* system, then the lookup terminates and the file system is returned.
*
* @param path
* the path to the file
* @param env
* a map of provider specific properties to configure the file system;
* may be empty
* @param loader
* the class loader to locate the provider or {@code null} to only
* attempt to locate an installed provider
*
* @return a new file system
*
* @throws ProviderNotFoundException
* if a provider supporting this file type cannot be located
* @throws ServiceConfigurationError
* when an error occurs while loading a service provider
* @throws IOException
* if an I/O error occurs
* @throws SecurityException
* if a security manager is installed and it denies an unspecified
* permission
*
* @since 13
*/
public static FileSystem newFileSystem(Path path, Map<String,?> env,
ClassLoader loader)
throws IOException
- csr of
-
JDK-8218875 (fs) Add FileSystems.newFileSystem(Path, Map<String, ?>) method
-
- Resolved
-
- relates to
-
JDK-8223771 (zipfs) FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
-
- Resolved
-