author | michaelm |
Fri, 30 Jan 2009 22:05:30 +0000 | |
changeset 1940 | e81514210873 |
parent 715 | f16baef3a20e |
child 3073 | 5e93bd389012 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
715 | 2 |
* Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. |
2 | 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. Sun designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 |
* have any questions. |
|
24 |
*/ |
|
25 |
||
26 |
package sun.misc; |
|
27 |
||
1940
e81514210873
4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents:
715
diff
changeset
|
28 |
import java.util.*; |
2 | 29 |
import java.util.jar.JarFile; |
30 |
import sun.misc.JarIndex; |
|
31 |
import sun.misc.InvalidJarIndexException; |
|
32 |
import sun.net.www.ParseUtil; |
|
33 |
import java.util.zip.ZipEntry; |
|
34 |
import java.util.jar.JarEntry; |
|
35 |
import java.util.jar.Manifest; |
|
36 |
import java.util.jar.Attributes; |
|
37 |
import java.util.jar.Attributes.Name; |
|
38 |
import java.net.JarURLConnection; |
|
39 |
import java.net.MalformedURLException; |
|
40 |
import java.net.URL; |
|
41 |
import java.net.URLConnection; |
|
42 |
import java.net.HttpURLConnection; |
|
43 |
import java.net.URLStreamHandler; |
|
44 |
import java.net.URLStreamHandlerFactory; |
|
1940
e81514210873
4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents:
715
diff
changeset
|
45 |
import java.io.*; |
2 | 46 |
import java.security.AccessController; |
47 |
import java.security.AccessControlException; |
|
48 |
import java.security.CodeSigner; |
|
49 |
import java.security.Permission; |
|
50 |
import java.security.PrivilegedAction; |
|
51 |
import java.security.PrivilegedExceptionAction; |
|
52 |
import java.security.cert.Certificate; |
|
53 |
import sun.misc.FileURLMapper; |
|
54 |
||
55 |
/** |
|
56 |
* This class is used to maintain a search path of URLs for loading classes |
|
57 |
* and resources from both JAR files and directories. |
|
58 |
* |
|
59 |
* @author David Connelly |
|
60 |
*/ |
|
61 |
public class URLClassPath { |
|
62 |
final static String USER_AGENT_JAVA_VERSION = "UA-Java-Version"; |
|
63 |
final static String JAVA_VERSION; |
|
64 |
private static final boolean DEBUG; |
|
65 |
||
66 |
static { |
|
67 |
JAVA_VERSION = java.security.AccessController.doPrivileged( |
|
68 |
new sun.security.action.GetPropertyAction("java.version")); |
|
69 |
DEBUG = (java.security.AccessController.doPrivileged( |
|
70 |
new sun.security.action.GetPropertyAction("sun.misc.URLClassPath.debug")) != null); |
|
71 |
} |
|
72 |
||
73 |
/* The original search path of URLs. */ |
|
51 | 74 |
private ArrayList<URL> path = new ArrayList<URL>(); |
2 | 75 |
|
76 |
/* The stack of unopened URLs */ |
|
51 | 77 |
Stack<URL> urls = new Stack<URL>(); |
2 | 78 |
|
79 |
/* The resulting search path of Loaders */ |
|
51 | 80 |
ArrayList<Loader> loaders = new ArrayList<Loader>(); |
2 | 81 |
|
82 |
/* Map of each URL opened to its corresponding Loader */ |
|
51 | 83 |
HashMap<URL, Loader> lmap = new HashMap<URL, Loader>(); |
2 | 84 |
|
85 |
/* The jar protocol handler to use when creating new URLs */ |
|
86 |
private URLStreamHandler jarHandler; |
|
87 |
||
1940
e81514210873
4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents:
715
diff
changeset
|
88 |
/* Whether this URLClassLoader has been closed yet */ |
e81514210873
4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents:
715
diff
changeset
|
89 |
private boolean closed = false; |
e81514210873
4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents:
715
diff
changeset
|
90 |
|
2 | 91 |
/** |
92 |
* Creates a new URLClassPath for the given URLs. The URLs will be |
|
93 |
* searched in the order specified for classes and resources. A URL |
|
94 |
* ending with a '/' is assumed to refer to a directory. Otherwise, |
|
95 |
* the URL is assumed to refer to a JAR file. |
|
96 |
* |
|
97 |
* @param urls the directory and JAR file URLs to search for classes |
|
98 |
* and resources |
|
99 |
* @param factory the URLStreamHandlerFactory to use when creating new URLs |
|
100 |
*/ |
|
101 |
public URLClassPath(URL[] urls, URLStreamHandlerFactory factory) { |
|
102 |
for (int i = 0; i < urls.length; i++) { |
|
103 |
path.add(urls[i]); |
|
104 |
} |
|
105 |
push(urls); |
|
106 |
if (factory != null) { |
|
107 |
jarHandler = factory.createURLStreamHandler("jar"); |
|
108 |
} |
|
109 |
} |
|
110 |
||
111 |
public URLClassPath(URL[] urls) { |
|
112 |
this(urls, null); |
|
113 |
} |
|
114 |
||
1940
e81514210873
4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents:
715
diff
changeset
|
115 |
public synchronized List<IOException> closeLoaders() { |
e81514210873
4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents:
715
diff
changeset
|
116 |
if (closed) { |
e81514210873
4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents:
715
diff
changeset
|
117 |
return Collections.emptyList(); |
e81514210873
4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents:
715
diff
changeset
|
118 |
} |
e81514210873
4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents:
715
diff
changeset
|
119 |
List<IOException> result = new LinkedList<IOException>(); |
e81514210873
4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents:
715
diff
changeset
|
120 |
for (Loader loader : loaders) { |
e81514210873
4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents:
715
diff
changeset
|
121 |
try { |
e81514210873
4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents:
715
diff
changeset
|
122 |
loader.close(); |
e81514210873
4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents:
715
diff
changeset
|
123 |
} catch (IOException e) { |
e81514210873
4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents:
715
diff
changeset
|
124 |
result.add (e); |
e81514210873
4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents:
715
diff
changeset
|
125 |
} |
e81514210873
4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents:
715
diff
changeset
|
126 |
} |
e81514210873
4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents:
715
diff
changeset
|
127 |
closed = true; |
e81514210873
4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents:
715
diff
changeset
|
128 |
return result; |
e81514210873
4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents:
715
diff
changeset
|
129 |
} |
e81514210873
4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents:
715
diff
changeset
|
130 |
|
2 | 131 |
/** |
132 |
* Appends the specified URL to the search path of directory and JAR |
|
133 |
* file URLs from which to load classes and resources. |
|
134 |
* <p> |
|
135 |
* If the URL specified is null or is already in the list of |
|
136 |
* URLs, then invoking this method has no effect. |
|
137 |
*/ |
|
138 |
public void addURL(URL url) { |
|
139 |
synchronized (urls) { |
|
140 |
if (url == null || path.contains(url)) |
|
141 |
return; |
|
142 |
||
143 |
urls.add(0, url); |
|
144 |
path.add(url); |
|
145 |
} |
|
146 |
} |
|
147 |
||
148 |
/** |
|
149 |
* Returns the original search path of URLs. |
|
150 |
*/ |
|
151 |
public URL[] getURLs() { |
|
152 |
synchronized (urls) { |
|
51 | 153 |
return path.toArray(new URL[path.size()]); |
2 | 154 |
} |
155 |
} |
|
156 |
||
157 |
/** |
|
158 |
* Finds the resource with the specified name on the URL search path |
|
159 |
* or null if not found or security check fails. |
|
160 |
* |
|
161 |
* @param name the name of the resource |
|
162 |
* @param check whether to perform a security check |
|
163 |
* @return a <code>URL</code> for the resource, or <code>null</code> |
|
164 |
* if the resource could not be found. |
|
165 |
*/ |
|
166 |
public URL findResource(String name, boolean check) { |
|
167 |
Loader loader; |
|
168 |
for (int i = 0; (loader = getLoader(i)) != null; i++) { |
|
169 |
URL url = loader.findResource(name, check); |
|
170 |
if (url != null) { |
|
171 |
return url; |
|
172 |
} |
|
173 |
} |
|
174 |
return null; |
|
175 |
} |
|
176 |
||
177 |
/** |
|
178 |
* Finds the first Resource on the URL search path which has the specified |
|
179 |
* name. Returns null if no Resource could be found. |
|
180 |
* |
|
181 |
* @param name the name of the Resource |
|
182 |
* @param check whether to perform a security check |
|
183 |
* @return the Resource, or null if not found |
|
184 |
*/ |
|
185 |
public Resource getResource(String name, boolean check) { |
|
186 |
if (DEBUG) { |
|
187 |
System.err.println("URLClassPath.getResource(\"" + name + "\")"); |
|
188 |
} |
|
189 |
||
190 |
Loader loader; |
|
191 |
for (int i = 0; (loader = getLoader(i)) != null; i++) { |
|
192 |
Resource res = loader.getResource(name, check); |
|
193 |
if (res != null) { |
|
194 |
return res; |
|
195 |
} |
|
196 |
} |
|
197 |
return null; |
|
198 |
} |
|
199 |
||
200 |
/** |
|
201 |
* Finds all resources on the URL search path with the given name. |
|
202 |
* Returns an enumeration of the URL objects. |
|
203 |
* |
|
204 |
* @param name the resource name |
|
205 |
* @return an Enumeration of all the urls having the specified name |
|
206 |
*/ |
|
51 | 207 |
public Enumeration<URL> findResources(final String name, |
2 | 208 |
final boolean check) { |
51 | 209 |
return new Enumeration<URL>() { |
2 | 210 |
private int index = 0; |
211 |
private URL url = null; |
|
212 |
||
213 |
private boolean next() { |
|
214 |
if (url != null) { |
|
215 |
return true; |
|
216 |
} else { |
|
217 |
Loader loader; |
|
218 |
while ((loader = getLoader(index++)) != null) { |
|
219 |
url = loader.findResource(name, check); |
|
220 |
if (url != null) { |
|
221 |
return true; |
|
222 |
} |
|
223 |
} |
|
224 |
return false; |
|
225 |
} |
|
226 |
} |
|
227 |
||
228 |
public boolean hasMoreElements() { |
|
229 |
return next(); |
|
230 |
} |
|
231 |
||
51 | 232 |
public URL nextElement() { |
2 | 233 |
if (!next()) { |
234 |
throw new NoSuchElementException(); |
|
235 |
} |
|
236 |
URL u = url; |
|
237 |
url = null; |
|
238 |
return u; |
|
239 |
} |
|
240 |
}; |
|
241 |
} |
|
242 |
||
243 |
public Resource getResource(String name) { |
|
244 |
return getResource(name, true); |
|
245 |
} |
|
246 |
||
247 |
/** |
|
248 |
* Finds all resources on the URL search path with the given name. |
|
249 |
* Returns an enumeration of the Resource objects. |
|
250 |
* |
|
251 |
* @param name the resource name |
|
252 |
* @return an Enumeration of all the resources having the specified name |
|
253 |
*/ |
|
51 | 254 |
public Enumeration<Resource> getResources(final String name, |
2 | 255 |
final boolean check) { |
51 | 256 |
return new Enumeration<Resource>() { |
2 | 257 |
private int index = 0; |
258 |
private Resource res = null; |
|
259 |
||
260 |
private boolean next() { |
|
261 |
if (res != null) { |
|
262 |
return true; |
|
263 |
} else { |
|
264 |
Loader loader; |
|
265 |
while ((loader = getLoader(index++)) != null) { |
|
266 |
res = loader.getResource(name, check); |
|
267 |
if (res != null) { |
|
268 |
return true; |
|
269 |
} |
|
270 |
} |
|
271 |
return false; |
|
272 |
} |
|
273 |
} |
|
274 |
||
275 |
public boolean hasMoreElements() { |
|
276 |
return next(); |
|
277 |
} |
|
278 |
||
51 | 279 |
public Resource nextElement() { |
2 | 280 |
if (!next()) { |
281 |
throw new NoSuchElementException(); |
|
282 |
} |
|
283 |
Resource r = res; |
|
284 |
res = null; |
|
285 |
return r; |
|
286 |
} |
|
287 |
}; |
|
288 |
} |
|
289 |
||
51 | 290 |
public Enumeration<Resource> getResources(final String name) { |
2 | 291 |
return getResources(name, true); |
292 |
} |
|
293 |
||
294 |
/* |
|
295 |
* Returns the Loader at the specified position in the URL search |
|
296 |
* path. The URLs are opened and expanded as needed. Returns null |
|
297 |
* if the specified index is out of range. |
|
298 |
*/ |
|
299 |
private synchronized Loader getLoader(int index) { |
|
1940
e81514210873
4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents:
715
diff
changeset
|
300 |
if (closed) { |
e81514210873
4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents:
715
diff
changeset
|
301 |
return null; |
e81514210873
4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents:
715
diff
changeset
|
302 |
} |
2 | 303 |
// Expand URL search path until the request can be satisfied |
304 |
// or the URL stack is empty. |
|
305 |
while (loaders.size() < index + 1) { |
|
306 |
// Pop the next URL from the URL stack |
|
307 |
URL url; |
|
308 |
synchronized (urls) { |
|
309 |
if (urls.empty()) { |
|
310 |
return null; |
|
311 |
} else { |
|
51 | 312 |
url = urls.pop(); |
2 | 313 |
} |
314 |
} |
|
315 |
// Skip this URL if it already has a Loader. (Loader |
|
316 |
// may be null in the case where URL has not been opened |
|
317 |
// but is referenced by a JAR index.) |
|
318 |
if (lmap.containsKey(url)) { |
|
319 |
continue; |
|
320 |
} |
|
321 |
// Otherwise, create a new Loader for the URL. |
|
322 |
Loader loader; |
|
323 |
try { |
|
324 |
loader = getLoader(url); |
|
325 |
// If the loader defines a local class path then add the |
|
326 |
// URLs to the list of URLs to be opened. |
|
327 |
URL[] urls = loader.getClassPath(); |
|
328 |
if (urls != null) { |
|
329 |
push(urls); |
|
330 |
} |
|
331 |
} catch (IOException e) { |
|
332 |
// Silently ignore for now... |
|
333 |
continue; |
|
334 |
} |
|
335 |
// Finally, add the Loader to the search path. |
|
336 |
loaders.add(loader); |
|
337 |
lmap.put(url, loader); |
|
338 |
} |
|
51 | 339 |
return loaders.get(index); |
2 | 340 |
} |
341 |
||
342 |
/* |
|
343 |
* Returns the Loader for the specified base URL. |
|
344 |
*/ |
|
345 |
private Loader getLoader(final URL url) throws IOException { |
|
346 |
try { |
|
51 | 347 |
return java.security.AccessController.doPrivileged( |
348 |
new java.security.PrivilegedExceptionAction<Loader>() { |
|
349 |
public Loader run() throws IOException { |
|
2 | 350 |
String file = url.getFile(); |
351 |
if (file != null && file.endsWith("/")) { |
|
352 |
if ("file".equals(url.getProtocol())) { |
|
353 |
return new FileLoader(url); |
|
354 |
} else { |
|
355 |
return new Loader(url); |
|
356 |
} |
|
357 |
} else { |
|
358 |
return new JarLoader(url, jarHandler, lmap); |
|
359 |
} |
|
360 |
} |
|
361 |
}); |
|
362 |
} catch (java.security.PrivilegedActionException pae) { |
|
363 |
throw (IOException)pae.getException(); |
|
364 |
} |
|
365 |
} |
|
366 |
||
367 |
/* |
|
368 |
* Pushes the specified URLs onto the list of unopened URLs. |
|
369 |
*/ |
|
370 |
private void push(URL[] us) { |
|
371 |
synchronized (urls) { |
|
372 |
for (int i = us.length - 1; i >= 0; --i) { |
|
373 |
urls.push(us[i]); |
|
374 |
} |
|
375 |
} |
|
376 |
} |
|
377 |
||
378 |
/** |
|
379 |
* Convert class path specification into an array of file URLs. |
|
380 |
* |
|
381 |
* The path of the file is encoded before conversion into URL |
|
382 |
* form so that reserved characters can safely appear in the path. |
|
383 |
*/ |
|
384 |
public static URL[] pathToURLs(String path) { |
|
385 |
StringTokenizer st = new StringTokenizer(path, File.pathSeparator); |
|
386 |
URL[] urls = new URL[st.countTokens()]; |
|
387 |
int count = 0; |
|
388 |
while (st.hasMoreTokens()) { |
|
389 |
File f = new File(st.nextToken()); |
|
390 |
try { |
|
391 |
f = new File(f.getCanonicalPath()); |
|
392 |
} catch (IOException x) { |
|
393 |
// use the non-canonicalized filename |
|
394 |
} |
|
395 |
try { |
|
396 |
urls[count++] = ParseUtil.fileToEncodedURL(f); |
|
397 |
} catch (IOException x) { } |
|
398 |
} |
|
399 |
||
400 |
if (urls.length != count) { |
|
401 |
URL[] tmp = new URL[count]; |
|
402 |
System.arraycopy(urls, 0, tmp, 0, count); |
|
403 |
urls = tmp; |
|
404 |
} |
|
405 |
return urls; |
|
406 |
} |
|
407 |
||
408 |
/* |
|
409 |
* Check whether the resource URL should be returned. |
|
410 |
* Return null on security check failure. |
|
411 |
* Called by java.net.URLClassLoader. |
|
412 |
*/ |
|
413 |
public URL checkURL(URL url) { |
|
414 |
try { |
|
415 |
check(url); |
|
416 |
} catch (Exception e) { |
|
417 |
return null; |
|
418 |
} |
|
419 |
||
420 |
return url; |
|
421 |
} |
|
422 |
||
423 |
/* |
|
424 |
* Check whether the resource URL should be returned. |
|
425 |
* Throw exception on failure. |
|
426 |
* Called internally within this file. |
|
427 |
*/ |
|
428 |
static void check(URL url) throws IOException { |
|
429 |
SecurityManager security = System.getSecurityManager(); |
|
430 |
if (security != null) { |
|
431 |
URLConnection urlConnection = url.openConnection(); |
|
432 |
Permission perm = urlConnection.getPermission(); |
|
433 |
if (perm != null) { |
|
434 |
try { |
|
435 |
security.checkPermission(perm); |
|
436 |
} catch (SecurityException se) { |
|
437 |
// fallback to checkRead/checkConnect for pre 1.2 |
|
438 |
// security managers |
|
439 |
if ((perm instanceof java.io.FilePermission) && |
|
440 |
perm.getActions().indexOf("read") != -1) { |
|
441 |
security.checkRead(perm.getName()); |
|
442 |
} else if ((perm instanceof |
|
443 |
java.net.SocketPermission) && |
|
444 |
perm.getActions().indexOf("connect") != -1) { |
|
445 |
URL locUrl = url; |
|
446 |
if (urlConnection instanceof JarURLConnection) { |
|
447 |
locUrl = ((JarURLConnection)urlConnection).getJarFileURL(); |
|
448 |
} |
|
449 |
security.checkConnect(locUrl.getHost(), |
|
450 |
locUrl.getPort()); |
|
451 |
} else { |
|
452 |
throw se; |
|
453 |
} |
|
454 |
} |
|
455 |
} |
|
456 |
} |
|
457 |
} |
|
458 |
||
459 |
/** |
|
460 |
* Inner class used to represent a loader of resources and classes |
|
461 |
* from a base URL. |
|
462 |
*/ |
|
1940
e81514210873
4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents:
715
diff
changeset
|
463 |
private static class Loader implements Closeable { |
2 | 464 |
private final URL base; |
465 |
||
466 |
/* |
|
467 |
* Creates a new Loader for the specified URL. |
|
468 |
*/ |
|
469 |
Loader(URL url) { |
|
470 |
base = url; |
|
471 |
} |
|
472 |
||
473 |
/* |
|
474 |
* Returns the base URL for this Loader. |
|
475 |
*/ |
|
476 |
URL getBaseURL() { |
|
477 |
return base; |
|
478 |
} |
|
479 |
||
480 |
URL findResource(final String name, boolean check) { |
|
481 |
URL url; |
|
482 |
try { |
|
483 |
url = new URL(base, ParseUtil.encodePath(name, false)); |
|
484 |
} catch (MalformedURLException e) { |
|
485 |
throw new IllegalArgumentException("name"); |
|
486 |
} |
|
487 |
||
488 |
try { |
|
489 |
if (check) { |
|
490 |
URLClassPath.check(url); |
|
491 |
} |
|
492 |
||
493 |
/* |
|
494 |
* For a HTTP connection we use the HEAD method to |
|
495 |
* check if the resource exists. |
|
496 |
*/ |
|
497 |
URLConnection uc = url.openConnection(); |
|
498 |
if (uc instanceof HttpURLConnection) { |
|
499 |
HttpURLConnection hconn = (HttpURLConnection)uc; |
|
500 |
hconn.setRequestMethod("HEAD"); |
|
501 |
if (hconn.getResponseCode() >= HttpURLConnection.HTTP_BAD_REQUEST) { |
|
502 |
return null; |
|
503 |
} |
|
504 |
} else { |
|
505 |
// our best guess for the other cases |
|
506 |
InputStream is = url.openStream(); |
|
507 |
is.close(); |
|
508 |
} |
|
509 |
return url; |
|
510 |
} catch (Exception e) { |
|
511 |
return null; |
|
512 |
} |
|
513 |
} |
|
514 |
||
515 |
Resource getResource(final String name, boolean check) { |
|
516 |
final URL url; |
|
517 |
try { |
|
518 |
url = new URL(base, ParseUtil.encodePath(name, false)); |
|
519 |
} catch (MalformedURLException e) { |
|
520 |
throw new IllegalArgumentException("name"); |
|
521 |
} |
|
522 |
final URLConnection uc; |
|
523 |
try { |
|
524 |
if (check) { |
|
525 |
URLClassPath.check(url); |
|
526 |
} |
|
527 |
uc = url.openConnection(); |
|
528 |
InputStream in = uc.getInputStream(); |
|
529 |
} catch (Exception e) { |
|
530 |
return null; |
|
531 |
} |
|
532 |
return new Resource() { |
|
533 |
public String getName() { return name; } |
|
534 |
public URL getURL() { return url; } |
|
535 |
public URL getCodeSourceURL() { return base; } |
|
536 |
public InputStream getInputStream() throws IOException { |
|
537 |
return uc.getInputStream(); |
|
538 |
} |
|
539 |
public int getContentLength() throws IOException { |
|
540 |
return uc.getContentLength(); |
|
541 |
} |
|
542 |
}; |
|
543 |
} |
|
544 |
||
545 |
/* |
|
546 |
* Returns the Resource for the specified name, or null if not |
|
547 |
* found or the caller does not have the permission to get the |
|
548 |
* resource. |
|
549 |
*/ |
|
550 |
Resource getResource(final String name) { |
|
551 |
return getResource(name, true); |
|
552 |
} |
|
553 |
||
554 |
/* |
|
1940
e81514210873
4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents:
715
diff
changeset
|
555 |
* close this loader and release all resources |
e81514210873
4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents:
715
diff
changeset
|
556 |
* method overridden in sub-classes |
e81514210873
4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents:
715
diff
changeset
|
557 |
*/ |
e81514210873
4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents:
715
diff
changeset
|
558 |
public void close () throws IOException {} |
e81514210873
4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents:
715
diff
changeset
|
559 |
|
e81514210873
4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents:
715
diff
changeset
|
560 |
/* |
2 | 561 |
* Returns the local class path for this loader, or null if none. |
562 |
*/ |
|
563 |
URL[] getClassPath() throws IOException { |
|
564 |
return null; |
|
565 |
} |
|
566 |
} |
|
567 |
||
568 |
/* |
|
569 |
* Inner class used to represent a Loader of resources from a JAR URL. |
|
570 |
*/ |
|
571 |
static class JarLoader extends Loader { |
|
572 |
private JarFile jar; |
|
573 |
private URL csu; |
|
574 |
private JarIndex index; |
|
575 |
private MetaIndex metaIndex; |
|
576 |
private URLStreamHandler handler; |
|
51 | 577 |
private HashMap<URL, Loader> lmap; |
1940
e81514210873
4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents:
715
diff
changeset
|
578 |
private boolean closed = false; |
2 | 579 |
|
580 |
/* |
|
581 |
* Creates a new JarLoader for the specified URL referring to |
|
582 |
* a JAR file. |
|
583 |
*/ |
|
51 | 584 |
JarLoader(URL url, URLStreamHandler jarHandler, |
585 |
HashMap<URL, Loader> loaderMap) |
|
2 | 586 |
throws IOException |
587 |
{ |
|
588 |
super(new URL("jar", "", -1, url + "!/", jarHandler)); |
|
589 |
csu = url; |
|
590 |
handler = jarHandler; |
|
591 |
lmap = loaderMap; |
|
592 |
||
593 |
if (!isOptimizable(url)) { |
|
594 |
ensureOpen(); |
|
595 |
} else { |
|
596 |
String fileName = url.getFile(); |
|
597 |
if (fileName != null) { |
|
598 |
fileName = ParseUtil.decode(fileName); |
|
599 |
File f = new File(fileName); |
|
600 |
metaIndex = MetaIndex.forJar(f); |
|
601 |
// If the meta index is found but the file is not |
|
602 |
// installed, set metaIndex to null. A typical |
|
603 |
// senario is charsets.jar which won't be installed |
|
604 |
// when the user is running in certain locale environment. |
|
605 |
// The side effect of null metaIndex will cause |
|
606 |
// ensureOpen get called so that IOException is thrown. |
|
607 |
if (metaIndex != null && !f.exists()) { |
|
608 |
metaIndex = null; |
|
609 |
} |
|
610 |
} |
|
611 |
||
612 |
// metaIndex is null when either there is no such jar file |
|
613 |
// entry recorded in meta-index file or such jar file is |
|
614 |
// missing in JRE. See bug 6340399. |
|
615 |
if (metaIndex == null) { |
|
616 |
ensureOpen(); |
|
617 |
} |
|
618 |
} |
|
619 |
} |
|
620 |
||
1940
e81514210873
4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents:
715
diff
changeset
|
621 |
@Override |
e81514210873
4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents:
715
diff
changeset
|
622 |
public void close () throws IOException { |
e81514210873
4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents:
715
diff
changeset
|
623 |
// closing is synchronized at higher level |
e81514210873
4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents:
715
diff
changeset
|
624 |
if (!closed) { |
e81514210873
4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents:
715
diff
changeset
|
625 |
closed = true; |
e81514210873
4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents:
715
diff
changeset
|
626 |
// in case not already open. |
e81514210873
4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents:
715
diff
changeset
|
627 |
ensureOpen(); |
e81514210873
4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents:
715
diff
changeset
|
628 |
jar.close(); |
e81514210873
4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents:
715
diff
changeset
|
629 |
} |
e81514210873
4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents:
715
diff
changeset
|
630 |
} |
e81514210873
4167874: URL-downloaded jar files can consume all available file descriptors
michaelm
parents:
715
diff
changeset
|
631 |
|
2 | 632 |
JarFile getJarFile () { |
633 |
return jar; |
|
634 |
} |
|
635 |
||
636 |
private boolean isOptimizable(URL url) { |
|
637 |
return "file".equals(url.getProtocol()); |
|
638 |
} |
|
639 |
||
640 |
private void ensureOpen() throws IOException { |
|
641 |
if (jar == null) { |
|
642 |
try { |
|
643 |
java.security.AccessController.doPrivileged( |
|
51 | 644 |
new java.security.PrivilegedExceptionAction<Void>() { |
645 |
public Void run() throws IOException { |
|
2 | 646 |
if (DEBUG) { |
647 |
System.err.println("Opening " + csu); |
|
648 |
Thread.dumpStack(); |
|
649 |
} |
|
650 |
||
651 |
jar = getJarFile(csu); |
|
652 |
index = JarIndex.getJarIndex(jar, metaIndex); |
|
653 |
if (index != null) { |
|
654 |
String[] jarfiles = index.getJarFiles(); |
|
655 |
// Add all the dependent URLs to the lmap so that loaders |
|
656 |
// will not be created for them by URLClassPath.getLoader(int) |
|
657 |
// if the same URL occurs later on the main class path. We set |
|
658 |
// Loader to null here to avoid creating a Loader for each |
|
659 |
// URL until we actually need to try to load something from them. |
|
660 |
for(int i = 0; i < jarfiles.length; i++) { |
|
661 |
try { |
|
662 |
URL jarURL = new URL(csu, jarfiles[i]); |
|
663 |
// If a non-null loader already exists, leave it alone. |
|
664 |
if (!lmap.containsKey(jarURL)) { |
|
665 |
lmap.put(jarURL, null); |
|
666 |
} |
|
667 |
} catch (MalformedURLException e) { |
|
668 |
continue; |
|
669 |
} |
|
670 |
} |
|
671 |
} |
|
672 |
return null; |
|
673 |
} |
|
674 |
} |
|
675 |
); |
|
676 |
} catch (java.security.PrivilegedActionException pae) { |
|
677 |
throw (IOException)pae.getException(); |
|
678 |
} |
|
679 |
} |
|
680 |
} |
|
681 |
||
682 |
private JarFile getJarFile(URL url) throws IOException { |
|
683 |
// Optimize case where url refers to a local jar file |
|
684 |
if (isOptimizable(url)) { |
|
685 |
FileURLMapper p = new FileURLMapper (url); |
|
686 |
if (!p.exists()) { |
|
687 |
throw new FileNotFoundException(p.getPath()); |
|
688 |
} |
|
689 |
return new JarFile (p.getPath()); |
|
690 |
} |
|
691 |
URLConnection uc = getBaseURL().openConnection(); |
|
692 |
uc.setRequestProperty(USER_AGENT_JAVA_VERSION, JAVA_VERSION); |
|
693 |
return ((JarURLConnection)uc).getJarFile(); |
|
694 |
} |
|
695 |
||
696 |
/* |
|
697 |
* Returns the index of this JarLoader if it exists. |
|
698 |
*/ |
|
699 |
JarIndex getIndex() { |
|
700 |
try { |
|
701 |
ensureOpen(); |
|
702 |
} catch (IOException e) { |
|
703 |
throw (InternalError) new InternalError().initCause(e); |
|
704 |
} |
|
705 |
return index; |
|
706 |
} |
|
707 |
||
708 |
/* |
|
709 |
* Creates the resource and if the check flag is set to true, checks if |
|
710 |
* is its okay to return the resource. |
|
711 |
*/ |
|
712 |
Resource checkResource(final String name, boolean check, |
|
713 |
final JarEntry entry) { |
|
714 |
||
715 |
final URL url; |
|
716 |
try { |
|
717 |
url = new URL(getBaseURL(), ParseUtil.encodePath(name, false)); |
|
718 |
if (check) { |
|
719 |
URLClassPath.check(url); |
|
720 |
} |
|
721 |
} catch (MalformedURLException e) { |
|
722 |
return null; |
|
723 |
// throw new IllegalArgumentException("name"); |
|
724 |
} catch (IOException e) { |
|
725 |
return null; |
|
726 |
} catch (AccessControlException e) { |
|
727 |
return null; |
|
728 |
} |
|
729 |
||
730 |
return new Resource() { |
|
731 |
public String getName() { return name; } |
|
732 |
public URL getURL() { return url; } |
|
733 |
public URL getCodeSourceURL() { return csu; } |
|
734 |
public InputStream getInputStream() throws IOException |
|
735 |
{ return jar.getInputStream(entry); } |
|
736 |
public int getContentLength() |
|
737 |
{ return (int)entry.getSize(); } |
|
738 |
public Manifest getManifest() throws IOException |
|
739 |
{ return jar.getManifest(); }; |
|
740 |
public Certificate[] getCertificates() |
|
741 |
{ return entry.getCertificates(); }; |
|
742 |
public CodeSigner[] getCodeSigners() |
|
743 |
{ return entry.getCodeSigners(); }; |
|
744 |
}; |
|
745 |
} |
|
746 |
||
747 |
||
748 |
/* |
|
749 |
* Returns true iff atleast one resource in the jar file has the same |
|
750 |
* package name as that of the specified resource name. |
|
751 |
*/ |
|
752 |
boolean validIndex(final String name) { |
|
753 |
String packageName = name; |
|
754 |
int pos; |
|
755 |
if((pos = name.lastIndexOf("/")) != -1) { |
|
756 |
packageName = name.substring(0, pos); |
|
757 |
} |
|
758 |
||
759 |
String entryName; |
|
760 |
ZipEntry entry; |
|
51 | 761 |
Enumeration<JarEntry> enum_ = jar.entries(); |
2 | 762 |
while (enum_.hasMoreElements()) { |
51 | 763 |
entry = enum_.nextElement(); |
2 | 764 |
entryName = entry.getName(); |
765 |
if((pos = entryName.lastIndexOf("/")) != -1) |
|
766 |
entryName = entryName.substring(0, pos); |
|
767 |
if (entryName.equals(packageName)) { |
|
768 |
return true; |
|
769 |
} |
|
770 |
} |
|
771 |
return false; |
|
772 |
} |
|
773 |
||
774 |
/* |
|
775 |
* Returns the URL for a resource with the specified name |
|
776 |
*/ |
|
777 |
URL findResource(final String name, boolean check) { |
|
778 |
Resource rsc = getResource(name, check); |
|
779 |
if (rsc != null) { |
|
780 |
return rsc.getURL(); |
|
781 |
} |
|
782 |
return null; |
|
783 |
} |
|
784 |
||
785 |
/* |
|
786 |
* Returns the JAR Resource for the specified name. |
|
787 |
*/ |
|
788 |
Resource getResource(final String name, boolean check) { |
|
789 |
if (metaIndex != null) { |
|
790 |
if (!metaIndex.mayContain(name)) { |
|
791 |
return null; |
|
792 |
} |
|
793 |
} |
|
794 |
||
795 |
try { |
|
796 |
ensureOpen(); |
|
797 |
} catch (IOException e) { |
|
798 |
throw (InternalError) new InternalError().initCause(e); |
|
799 |
} |
|
800 |
final JarEntry entry = jar.getJarEntry(name); |
|
801 |
if (entry != null) |
|
802 |
return checkResource(name, check, entry); |
|
803 |
||
804 |
if (index == null) |
|
805 |
return null; |
|
806 |
||
51 | 807 |
HashSet<URL> visited = new HashSet<URL>(); |
2 | 808 |
return getResource(name, check, visited); |
809 |
} |
|
810 |
||
811 |
/* |
|
812 |
* Version of getResource() that tracks the jar files that have been |
|
813 |
* visited by linking through the index files. This helper method uses |
|
814 |
* a HashSet to store the URLs of jar files that have been searched and |
|
815 |
* uses it to avoid going into an infinite loop, looking for a |
|
816 |
* non-existent resource |
|
817 |
*/ |
|
818 |
Resource getResource(final String name, boolean check, |
|
51 | 819 |
Set<URL> visited) { |
2 | 820 |
|
821 |
Resource res; |
|
822 |
Object[] jarFiles; |
|
823 |
boolean done = false; |
|
824 |
int count = 0; |
|
825 |
LinkedList jarFilesList = null; |
|
826 |
||
827 |
/* If there no jar files in the index that can potential contain |
|
828 |
* this resource then return immediately. |
|
829 |
*/ |
|
830 |
if((jarFilesList = index.get(name)) == null) |
|
831 |
return null; |
|
832 |
||
833 |
do { |
|
834 |
jarFiles = jarFilesList.toArray(); |
|
835 |
int size = jarFilesList.size(); |
|
836 |
/* loop through the mapped jar file list */ |
|
837 |
while(count < size) { |
|
838 |
String jarName = (String)jarFiles[count++]; |
|
839 |
JarLoader newLoader; |
|
840 |
final URL url; |
|
841 |
||
842 |
try{ |
|
843 |
url = new URL(csu, jarName); |
|
844 |
if ((newLoader = (JarLoader)lmap.get(url)) == null) { |
|
845 |
/* no loader has been set up for this jar file |
|
846 |
* before |
|
847 |
*/ |
|
51 | 848 |
newLoader = AccessController.doPrivileged( |
849 |
new PrivilegedExceptionAction<JarLoader>() { |
|
850 |
public JarLoader run() throws IOException { |
|
2 | 851 |
return new JarLoader(url, handler, |
852 |
lmap); |
|
853 |
} |
|
854 |
}); |
|
855 |
||
856 |
/* this newly opened jar file has its own index, |
|
857 |
* merge it into the parent's index, taking into |
|
858 |
* account the relative path. |
|
859 |
*/ |
|
860 |
JarIndex newIndex = newLoader.getIndex(); |
|
861 |
if(newIndex != null) { |
|
862 |
int pos = jarName.lastIndexOf("/"); |
|
863 |
newIndex.merge(this.index, (pos == -1 ? |
|
864 |
null : jarName.substring(0, pos + 1))); |
|
865 |
} |
|
866 |
||
867 |
/* put it in the global hashtable */ |
|
868 |
lmap.put(url, newLoader); |
|
869 |
} |
|
870 |
} catch (java.security.PrivilegedActionException pae) { |
|
871 |
continue; |
|
872 |
} catch (MalformedURLException e) { |
|
873 |
continue; |
|
874 |
} |
|
875 |
||
876 |
||
877 |
/* Note that the addition of the url to the list of visited |
|
878 |
* jars incorporates a check for presence in the hashmap |
|
879 |
*/ |
|
880 |
boolean visitedURL = !visited.add(url); |
|
881 |
if (!visitedURL) { |
|
882 |
try { |
|
883 |
newLoader.ensureOpen(); |
|
884 |
} catch (IOException e) { |
|
885 |
throw (InternalError) new InternalError().initCause(e); |
|
886 |
} |
|
887 |
final JarEntry entry = newLoader.jar.getJarEntry(name); |
|
888 |
if (entry != null) { |
|
889 |
return newLoader.checkResource(name, check, entry); |
|
890 |
} |
|
891 |
||
892 |
/* Verify that at least one other resource with the |
|
893 |
* same package name as the lookedup resource is |
|
894 |
* present in the new jar |
|
895 |
*/ |
|
896 |
if (!newLoader.validIndex(name)) { |
|
897 |
/* the mapping is wrong */ |
|
898 |
throw new InvalidJarIndexException("Invalid index"); |
|
899 |
} |
|
900 |
} |
|
901 |
||
902 |
/* If newLoader is the current loader or if it is a |
|
903 |
* loader that has already been searched or if the new |
|
904 |
* loader does not have an index then skip it |
|
905 |
* and move on to the next loader. |
|
906 |
*/ |
|
907 |
if (visitedURL || newLoader == this || |
|
908 |
newLoader.getIndex() == null) { |
|
909 |
continue; |
|
910 |
} |
|
911 |
||
912 |
/* Process the index of the new loader |
|
913 |
*/ |
|
914 |
if((res = newLoader.getResource(name, check, visited)) |
|
915 |
!= null) { |
|
916 |
return res; |
|
917 |
} |
|
918 |
} |
|
919 |
// Get the list of jar files again as the list could have grown |
|
920 |
// due to merging of index files. |
|
921 |
jarFilesList = index.get(name); |
|
922 |
||
923 |
// If the count is unchanged, we are done. |
|
924 |
} while(count < jarFilesList.size()); |
|
925 |
return null; |
|
926 |
} |
|
927 |
||
928 |
||
929 |
/* |
|
930 |
* Returns the JAR file local class path, or null if none. |
|
931 |
*/ |
|
932 |
URL[] getClassPath() throws IOException { |
|
933 |
if (index != null) { |
|
934 |
return null; |
|
935 |
} |
|
936 |
||
937 |
if (metaIndex != null) { |
|
938 |
return null; |
|
939 |
} |
|
940 |
||
941 |
ensureOpen(); |
|
942 |
parseExtensionsDependencies(); |
|
943 |
if (SharedSecrets.javaUtilJarAccess().jarFileHasClassPathAttribute(jar)) { // Only get manifest when necessary |
|
944 |
Manifest man = jar.getManifest(); |
|
945 |
if (man != null) { |
|
946 |
Attributes attr = man.getMainAttributes(); |
|
947 |
if (attr != null) { |
|
948 |
String value = attr.getValue(Name.CLASS_PATH); |
|
949 |
if (value != null) { |
|
950 |
return parseClassPath(csu, value); |
|
951 |
} |
|
952 |
} |
|
953 |
} |
|
954 |
} |
|
955 |
return null; |
|
956 |
} |
|
957 |
||
958 |
/* |
|
959 |
* parse the standard extension dependencies |
|
960 |
*/ |
|
961 |
private void parseExtensionsDependencies() throws IOException { |
|
962 |
ExtensionDependency.checkExtensionsDependencies(jar); |
|
963 |
} |
|
964 |
||
965 |
/* |
|
966 |
* Parses value of the Class-Path manifest attribute and returns |
|
967 |
* an array of URLs relative to the specified base URL. |
|
968 |
*/ |
|
969 |
private URL[] parseClassPath(URL base, String value) |
|
970 |
throws MalformedURLException |
|
971 |
{ |
|
972 |
StringTokenizer st = new StringTokenizer(value); |
|
973 |
URL[] urls = new URL[st.countTokens()]; |
|
974 |
int i = 0; |
|
975 |
while (st.hasMoreTokens()) { |
|
976 |
String path = st.nextToken(); |
|
977 |
urls[i] = new URL(base, path); |
|
978 |
i++; |
|
979 |
} |
|
980 |
return urls; |
|
981 |
} |
|
982 |
} |
|
983 |
||
984 |
/* |
|
985 |
* Inner class used to represent a loader of classes and resources |
|
986 |
* from a file URL that refers to a directory. |
|
987 |
*/ |
|
988 |
private static class FileLoader extends Loader { |
|
495
d612e90c3ebc
6687919: REGRESSION : Classloader can handle any resource which is not included in classpath
chegar
parents:
51
diff
changeset
|
989 |
/* Canonicalized File */ |
2 | 990 |
private File dir; |
991 |
||
992 |
FileLoader(URL url) throws IOException { |
|
993 |
super(url); |
|
994 |
if (!"file".equals(url.getProtocol())) { |
|
995 |
throw new IllegalArgumentException("url"); |
|
996 |
} |
|
997 |
String path = url.getFile().replace('/', File.separatorChar); |
|
998 |
path = ParseUtil.decode(path); |
|
495
d612e90c3ebc
6687919: REGRESSION : Classloader can handle any resource which is not included in classpath
chegar
parents:
51
diff
changeset
|
999 |
dir = (new File(path)).getCanonicalFile(); |
2 | 1000 |
} |
1001 |
||
1002 |
/* |
|
1003 |
* Returns the URL for a resource with the specified name |
|
1004 |
*/ |
|
1005 |
URL findResource(final String name, boolean check) { |
|
1006 |
Resource rsc = getResource(name, check); |
|
1007 |
if (rsc != null) { |
|
1008 |
return rsc.getURL(); |
|
1009 |
} |
|
1010 |
return null; |
|
1011 |
} |
|
1012 |
||
1013 |
Resource getResource(final String name, boolean check) { |
|
1014 |
final URL url; |
|
1015 |
try { |
|
1016 |
URL normalizedBase = new URL(getBaseURL(), "."); |
|
1017 |
url = new URL(getBaseURL(), ParseUtil.encodePath(name, false)); |
|
1018 |
||
1019 |
if (url.getFile().startsWith(normalizedBase.getFile()) == false) { |
|
1020 |
// requested resource had ../..'s in path |
|
1021 |
return null; |
|
1022 |
} |
|
1023 |
||
1024 |
if (check) |
|
1025 |
URLClassPath.check(url); |
|
495
d612e90c3ebc
6687919: REGRESSION : Classloader can handle any resource which is not included in classpath
chegar
parents:
51
diff
changeset
|
1026 |
|
d612e90c3ebc
6687919: REGRESSION : Classloader can handle any resource which is not included in classpath
chegar
parents:
51
diff
changeset
|
1027 |
final File file; |
d612e90c3ebc
6687919: REGRESSION : Classloader can handle any resource which is not included in classpath
chegar
parents:
51
diff
changeset
|
1028 |
if (name.indexOf("..") != -1) { |
d612e90c3ebc
6687919: REGRESSION : Classloader can handle any resource which is not included in classpath
chegar
parents:
51
diff
changeset
|
1029 |
file = (new File(dir, name.replace('/', File.separatorChar))) |
d612e90c3ebc
6687919: REGRESSION : Classloader can handle any resource which is not included in classpath
chegar
parents:
51
diff
changeset
|
1030 |
.getCanonicalFile(); |
d612e90c3ebc
6687919: REGRESSION : Classloader can handle any resource which is not included in classpath
chegar
parents:
51
diff
changeset
|
1031 |
if ( !((file.getPath()).startsWith(dir.getPath())) ) { |
d612e90c3ebc
6687919: REGRESSION : Classloader can handle any resource which is not included in classpath
chegar
parents:
51
diff
changeset
|
1032 |
/* outside of base dir */ |
d612e90c3ebc
6687919: REGRESSION : Classloader can handle any resource which is not included in classpath
chegar
parents:
51
diff
changeset
|
1033 |
return null; |
d612e90c3ebc
6687919: REGRESSION : Classloader can handle any resource which is not included in classpath
chegar
parents:
51
diff
changeset
|
1034 |
} |
d612e90c3ebc
6687919: REGRESSION : Classloader can handle any resource which is not included in classpath
chegar
parents:
51
diff
changeset
|
1035 |
} else { |
d612e90c3ebc
6687919: REGRESSION : Classloader can handle any resource which is not included in classpath
chegar
parents:
51
diff
changeset
|
1036 |
file = new File(dir, name.replace('/', File.separatorChar)); |
d612e90c3ebc
6687919: REGRESSION : Classloader can handle any resource which is not included in classpath
chegar
parents:
51
diff
changeset
|
1037 |
} |
d612e90c3ebc
6687919: REGRESSION : Classloader can handle any resource which is not included in classpath
chegar
parents:
51
diff
changeset
|
1038 |
|
2 | 1039 |
if (file.exists()) { |
1040 |
return new Resource() { |
|
1041 |
public String getName() { return name; }; |
|
1042 |
public URL getURL() { return url; }; |
|
1043 |
public URL getCodeSourceURL() { return getBaseURL(); }; |
|
1044 |
public InputStream getInputStream() throws IOException |
|
1045 |
{ return new FileInputStream(file); }; |
|
1046 |
public int getContentLength() throws IOException |
|
1047 |
{ return (int)file.length(); }; |
|
1048 |
}; |
|
1049 |
} |
|
1050 |
} catch (Exception e) { |
|
1051 |
return null; |
|
1052 |
} |
|
1053 |
return null; |
|
1054 |
} |
|
1055 |
} |
|
1056 |
} |