< prev index next >

src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystemProvider.java

Print this page

        

@@ -51,10 +51,12 @@
 /**
  * @author Xueming Shen, Rajendra Gutupalli, Jaya Hangal
  */
 public class ZipFileSystemProvider extends FileSystemProvider {
 
+    protected static final String RELEASE_VERSION = "releaseVersion";
+    protected static final String MULTI_RELEASE = "multi-release";
     private final Map<Path, ZipFileSystem> filesystems = new HashMap<>();
 
     public ZipFileSystemProvider() {}
 
     @Override

@@ -102,24 +104,11 @@
             if (ensureFile(path)) {
                 realPath = path.toRealPath();
                 if (filesystems.containsKey(realPath))
                     throw new FileSystemAlreadyExistsException();
             }
-            ZipFileSystem zipfs;
-            try {
-                if (env.containsKey("multi-release")) {
-                    zipfs = new JarFileSystem(this, path, env);
-                } else {
-                    zipfs = new ZipFileSystem(this, path, env);
-                }
-            } catch (ZipException ze) {
-                String pname = path.toString();
-                if (pname.endsWith(".zip") || pname.endsWith(".jar"))
-                    throw ze;
-                // assume NOT a zip/jar file
-                throw new UnsupportedOperationException();
-            }
+            ZipFileSystem zipfs = getZipFileSystem(path, env);
             if (realPath == null) {  // newly created
                 realPath = path.toRealPath();
             }
             filesystems.put(realPath, zipfs);
             return zipfs;

@@ -129,24 +118,30 @@
     @Override
     public FileSystem newFileSystem(Path path, Map<String, ?> env)
         throws IOException
     {
         ensureFile(path);
-        try {
+        ZipFileSystem zipfs = getZipFileSystem(path, env);
+        return zipfs;
+    }
+
+    private ZipFileSystem getZipFileSystem(Path path, Map<String, ?> env) throws IOException {
             ZipFileSystem zipfs;
-            if (env.containsKey("multi-release")) {
+        try {
+            if (env.containsKey(RELEASE_VERSION) ||
+                    env.containsKey(MULTI_RELEASE)) {
                 zipfs = new JarFileSystem(this, path, env);
             } else {
                 zipfs = new ZipFileSystem(this, path, env);
             }
-            return zipfs;
         } catch (ZipException ze) {
             String pname = path.toString();
             if (pname.endsWith(".zip") || pname.endsWith(".jar"))
                 throw ze;
             throw new UnsupportedOperationException();
         }
+        return zipfs;
     }
 
     @Override
     public Path getPath(URI uri) {
         String spec = uri.getSchemeSpecificPart();
< prev index next >