< prev index next >

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

Print this page
rev 51534 : 8034802: (zipfs) newFileSystem throws UOE when the zip file is located in a custom file system
Reviewed-by: xiaofeya, clanger
   1 /*
   2  * Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 107                 }
 108             } catch (ZipException ze) {
 109                 String pname = path.toString();
 110                 if (pname.endsWith(".zip") || pname.endsWith(".jar"))
 111                     throw ze;
 112                 // assume NOT a zip/jar file
 113                 throw new UnsupportedOperationException();
 114             }
 115             if (realPath == null) {  // newly created
 116                 realPath = path.toRealPath();
 117             }
 118             filesystems.put(realPath, zipfs);
 119             return zipfs;
 120         }
 121     }
 122 
 123     @Override
 124     public FileSystem newFileSystem(Path path, Map<String, ?> env)
 125         throws IOException
 126     {
 127         if (path.getFileSystem() != FileSystems.getDefault()) {
 128             throw new UnsupportedOperationException();
 129         }
 130         ensureFile(path);
 131          try {
 132              ZipFileSystem zipfs;
 133              if (env.containsKey("multi-release")) {
 134                  zipfs = new JarFileSystem(this, path, env);
 135              } else {
 136                  zipfs = new ZipFileSystem(this, path, env);
 137              }
 138             return zipfs;
 139         } catch (ZipException ze) {
 140             String pname = path.toString();
 141             if (pname.endsWith(".zip") || pname.endsWith(".jar"))
 142                 throw ze;
 143             throw new UnsupportedOperationException();
 144         }
 145     }
 146 
 147     @Override
 148     public Path getPath(URI uri) {
 149         String spec = uri.getSchemeSpecificPart();


   1 /*
   2  * Copyright (c) 2009, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 107                 }
 108             } catch (ZipException ze) {
 109                 String pname = path.toString();
 110                 if (pname.endsWith(".zip") || pname.endsWith(".jar"))
 111                     throw ze;
 112                 // assume NOT a zip/jar file
 113                 throw new UnsupportedOperationException();
 114             }
 115             if (realPath == null) {  // newly created
 116                 realPath = path.toRealPath();
 117             }
 118             filesystems.put(realPath, zipfs);
 119             return zipfs;
 120         }
 121     }
 122 
 123     @Override
 124     public FileSystem newFileSystem(Path path, Map<String, ?> env)
 125         throws IOException
 126     {



 127         ensureFile(path);
 128          try {
 129              ZipFileSystem zipfs;
 130              if (env.containsKey("multi-release")) {
 131                  zipfs = new JarFileSystem(this, path, env);
 132              } else {
 133                  zipfs = new ZipFileSystem(this, path, env);
 134              }
 135             return zipfs;
 136         } catch (ZipException ze) {
 137             String pname = path.toString();
 138             if (pname.endsWith(".zip") || pname.endsWith(".jar"))
 139                 throw ze;
 140             throw new UnsupportedOperationException();
 141         }
 142     }
 143 
 144     @Override
 145     public Path getPath(URI uri) {
 146         String spec = uri.getSchemeSpecificPart();


< prev index next >