< prev index next >

src/java.base/share/classes/jdk/internal/jrtfs/JrtFileSystemProvider.java

Print this page




 107         if (env.containsKey("java.home")) {
 108             return newFileSystem((String)env.get("java.home"), uri, env);
 109         } else {
 110             return new JrtFileSystem(this, env);
 111         }
 112     }
 113 
 114     private static final String JRT_FS_JAR = "jrt-fs.jar";
 115     private FileSystem newFileSystem(String targetHome, URI uri, Map<String, ?> env)
 116             throws IOException {
 117         Objects.requireNonNull(targetHome);
 118         Path jrtfs = FileSystems.getDefault().getPath(targetHome, JRT_FS_JAR);
 119         if (Files.notExists(jrtfs)) {
 120             throw new IOException(jrtfs.toString() + " not exist");
 121         }
 122         Map<String,?> newEnv = new HashMap<>(env);
 123         newEnv.remove("java.home");
 124         ClassLoader cl = newJrtFsLoader(jrtfs);
 125         try {
 126             Class<?> c = Class.forName(JrtFileSystemProvider.class.getName(), false, cl);
 127             return ((FileSystemProvider)c.newInstance()).newFileSystem(uri, newEnv);


 128         } catch (ClassNotFoundException |
 129                  IllegalAccessException |
 130                  InstantiationException e) {
 131             throw new IOException(e);
 132         }
 133     }
 134 
 135     private static class JrtFsLoader extends URLClassLoader {
 136         JrtFsLoader(URL[] urls) {
 137             super(urls);
 138         }
 139         @Override
 140         protected Class<?> loadClass(String cn, boolean resolve)
 141                 throws ClassNotFoundException
 142         {
 143             Class<?> c = findLoadedClass(cn);
 144             if (c == null) {
 145                 URL u = findResource(cn.replace('.', '/') + ".class");
 146                 if (u != null) {
 147                     c = findClass(cn);




 107         if (env.containsKey("java.home")) {
 108             return newFileSystem((String)env.get("java.home"), uri, env);
 109         } else {
 110             return new JrtFileSystem(this, env);
 111         }
 112     }
 113 
 114     private static final String JRT_FS_JAR = "jrt-fs.jar";
 115     private FileSystem newFileSystem(String targetHome, URI uri, Map<String, ?> env)
 116             throws IOException {
 117         Objects.requireNonNull(targetHome);
 118         Path jrtfs = FileSystems.getDefault().getPath(targetHome, JRT_FS_JAR);
 119         if (Files.notExists(jrtfs)) {
 120             throw new IOException(jrtfs.toString() + " not exist");
 121         }
 122         Map<String,?> newEnv = new HashMap<>(env);
 123         newEnv.remove("java.home");
 124         ClassLoader cl = newJrtFsLoader(jrtfs);
 125         try {
 126             Class<?> c = Class.forName(JrtFileSystemProvider.class.getName(), false, cl);
 127             @SuppressWarnings("deprecation")
 128             Object tmp = c.newInstance();
 129             return ((FileSystemProvider)tmp).newFileSystem(uri, newEnv);
 130         } catch (ClassNotFoundException |
 131                  IllegalAccessException |
 132                  InstantiationException e) {
 133             throw new IOException(e);
 134         }
 135     }
 136 
 137     private static class JrtFsLoader extends URLClassLoader {
 138         JrtFsLoader(URL[] urls) {
 139             super(urls);
 140         }
 141         @Override
 142         protected Class<?> loadClass(String cn, boolean resolve)
 143                 throws ClassNotFoundException
 144         {
 145             Class<?> c = findLoadedClass(cn);
 146             if (c == null) {
 147                 URL u = findResource(cn.replace('.', '/') + ".class");
 148                 if (u != null) {
 149                     c = findClass(cn);


< prev index next >