63 static JarFile getJarFile(URL url) throws IOException { |
63 static JarFile getJarFile(URL url) throws IOException { |
64 return getJarFile(url, null); |
64 return getJarFile(url, null); |
65 } |
65 } |
66 |
66 |
67 static JarFile getJarFile(URL url, URLJarFileCloseController closeController) throws IOException { |
67 static JarFile getJarFile(URL url, URLJarFileCloseController closeController) throws IOException { |
68 if (isFileURL(url)) |
68 if (isFileURL(url)) { |
69 return new URLJarFile(url, closeController); |
69 Release version = "runtime".equals(url.getRef()) ? Release.RUNTIME : Release.BASE; |
70 else { |
70 return new URLJarFile(url, closeController, version); |
|
71 } else { |
71 return retrieve(url, closeController); |
72 return retrieve(url, closeController); |
72 } |
73 } |
73 } |
74 } |
74 |
75 |
75 /* |
76 /* |
87 public URLJarFile(File file, URLJarFileCloseController closeController) throws IOException { |
88 public URLJarFile(File file, URLJarFileCloseController closeController) throws IOException { |
88 super(file, true, ZipFile.OPEN_READ | ZipFile.OPEN_DELETE); |
89 super(file, true, ZipFile.OPEN_READ | ZipFile.OPEN_DELETE); |
89 this.closeController = closeController; |
90 this.closeController = closeController; |
90 } |
91 } |
91 |
92 |
92 private URLJarFile(URL url, URLJarFileCloseController closeController) throws IOException { |
93 private URLJarFile(File file, URLJarFileCloseController closeController, Release version) throws IOException { |
93 super(ParseUtil.decode(url.getFile())); |
94 super(file, true, ZipFile.OPEN_READ | ZipFile.OPEN_DELETE, version); |
|
95 this.closeController = closeController; |
|
96 } |
|
97 |
|
98 private URLJarFile(URL url, URLJarFileCloseController closeController, Release version) throws IOException { |
|
99 super(new File(ParseUtil.decode(url.getFile())), true, ZipFile.OPEN_READ, version); |
94 this.closeController = closeController; |
100 this.closeController = closeController; |
95 } |
101 } |
96 |
102 |
97 private static boolean isFileURL(URL url) { |
103 private static boolean isFileURL(URL url) { |
98 if (url.getProtocol().equalsIgnoreCase("file")) { |
104 if (url.getProtocol().equalsIgnoreCase("file")) { |
177 |
183 |
178 /** |
184 /** |
179 * Given a URL, retrieves a JAR file, caches it to disk, and creates a |
185 * Given a URL, retrieves a JAR file, caches it to disk, and creates a |
180 * cached JAR file object. |
186 * cached JAR file object. |
181 */ |
187 */ |
182 private static JarFile retrieve(final URL url) throws IOException { |
|
183 return retrieve(url, null); |
|
184 } |
|
185 |
|
186 /** |
|
187 * Given a URL, retrieves a JAR file, caches it to disk, and creates a |
|
188 * cached JAR file object. |
|
189 */ |
|
190 private static JarFile retrieve(final URL url, final URLJarFileCloseController closeController) throws IOException { |
188 private static JarFile retrieve(final URL url, final URLJarFileCloseController closeController) throws IOException { |
191 /* |
189 /* |
192 * See if interface is set, then call retrieve function of the class |
190 * See if interface is set, then call retrieve function of the class |
193 * that implements URLJarFileCallBack interface (sun.plugin - to |
191 * that implements URLJarFileCallBack interface (sun.plugin - to |
194 * handle the cache failure for JARJAR file.) |
192 * handle the cache failure for JARJAR file.) |
200 |
198 |
201 else |
199 else |
202 { |
200 { |
203 |
201 |
204 JarFile result = null; |
202 JarFile result = null; |
|
203 Release version = "runtime".equals(url.getRef()) ? Release.RUNTIME : Release.BASE; |
205 |
204 |
206 /* get the stream before asserting privileges */ |
205 /* get the stream before asserting privileges */ |
207 try (final InputStream in = url.openConnection().getInputStream()) { |
206 try (final InputStream in = url.openConnection().getInputStream()) { |
208 result = AccessController.doPrivileged( |
207 result = AccessController.doPrivileged( |
209 new PrivilegedExceptionAction<>() { |
208 new PrivilegedExceptionAction<>() { |
210 public JarFile run() throws IOException { |
209 public JarFile run() throws IOException { |
211 Path tmpFile = Files.createTempFile("jar_cache", null); |
210 Path tmpFile = Files.createTempFile("jar_cache", null); |
212 try { |
211 try { |
213 Files.copy(in, tmpFile, StandardCopyOption.REPLACE_EXISTING); |
212 Files.copy(in, tmpFile, StandardCopyOption.REPLACE_EXISTING); |
214 JarFile jarFile = new URLJarFile(tmpFile.toFile(), closeController); |
213 JarFile jarFile = new URLJarFile(tmpFile.toFile(), closeController, version); |
215 tmpFile.toFile().deleteOnExit(); |
214 tmpFile.toFile().deleteOnExit(); |
216 return jarFile; |
215 return jarFile; |
217 } catch (Throwable thr) { |
216 } catch (Throwable thr) { |
218 try { |
217 try { |
219 Files.delete(tmpFile); |
218 Files.delete(tmpFile); |