Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8219793

(fs) Add FileSystems.newFileSystem(Path, Map<String, ?>) method

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 13
    • core-libs
    • None
    • source
    • low
    • Hide
      Existing code that is written similar to:
       
      Path x = ...
      FileSystem fs = FileSystems.newFileSystem(x, null)

      Will have to be modified to pass a ClassLoader variable or cast the null to ClassLoader.

      We believe this is a niche case with very limited impact given the Zip File System was not supported until JDK 9. In most existing cases the code can then be changed to the one-argument newFileSystem(Path) method.
      Show
      Existing code that is written similar to:   Path x = ... FileSystem fs = FileSystems.newFileSystem(x, null) Will have to be modified to pass a ClassLoader variable or cast the null to ClassLoader. We believe this is a niche case with very limited impact given the Zip File System was not supported until JDK 9. In most existing cases the code can then be changed to the one-argument newFileSystem(Path) method.
    • Java API
    • SE

      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

            lancea Lance Andersen
            lancea Lance Andersen
            Alan Bateman, Brian Burkhalter, Christoph Langer
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: