|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.lang.ClassLoader
java.security.SecureClassLoader
java.net.URLClassLoader
edu.emory.mathcs.util.classloader.URIClassLoader
Equivalent of java.net.URLClassloader but without bugs related to ill-formed URLs and with customizable JAR caching policy. The standard URLClassLoader accepts URLs containing spaces and other characters which are forbidden in the URI syntax, according to the RFC 2396. As a workaround to this problem, Java escapes and un-escapes URLs in various arbitrary places; however, this is inconsistent and leads to numerous problems with URLs referring to local files with spaces in the path. SUN acknowledges the problem, but refuses to modify the behavior for compatibility reasons; see Java Bug Parade 4273532, 4466485.
Additionally, the JAR caching policy used by URLClassLoader is system-wide and inflexible: once downloaded JAR files are never re-downloaded, even if one creates a fresh instance of the class loader that happens to have the same URL in its search path. In fact, that policy is a security vulnerability: it is possible to crash any URL class loader, thus affecting potentially separate part of the system, by creating URL connection to one of the URLs of that class loader search path and closing the associated JAR file. See Java Bug Parade 4405789, 4388666, 4639900.
This class avoids these problems by 1) using URIs instead of URLs for the search path (thus enforcing strict syntax conformance and defining precise escaping semantics), and 2) using custom URLStreamHandler which ensures per-classloader JAR caching policy.
File.toURL()
,
File.toURI()
Constructor Summary | |
URIClassLoader(java.net.URI[] uris)
Creates URIClassLoader with the specified search path. |
|
URIClassLoader(java.net.URI[] uris,
java.lang.ClassLoader parent)
Creates URIClassLoader with the specified search path and parent class loader. |
|
URIClassLoader(java.net.URI[] uris,
java.lang.ClassLoader parent,
java.net.URLStreamHandler jarHandler)
Creates URIClassLoader with the specified search path and parent class loader. |
|
URIClassLoader(java.net.URI[] uris,
java.net.URLStreamHandler jarHandler)
Creates URIClassLoader with the specified search path. |
Method Summary | |
protected void |
addURI(java.net.URI uri)
Add specified URI at the end of the search path. |
protected void |
addURL(java.net.URL url)
Deprecated. use addURI |
protected java.lang.Class |
defineClass(java.lang.String name,
ResourceHandle h)
|
protected java.lang.Class |
findClass(java.lang.String name)
Finds and loads the class with the specified name. |
protected java.lang.String |
findLibrary(java.lang.String libname)
Returns the absolute path name of a native library. |
java.net.URL |
findResource(java.lang.String name)
Finds the resource with the specified name. |
java.util.Enumeration |
findResources(java.lang.String name)
Returns an Enumeration of URLs representing all of the resources having the specified name. |
protected ResourceHandle |
getClassHandle(java.lang.String name)
Finds the ResourceHandle object for the class with the specified name. |
protected java.net.URLStreamHandler |
getJarHandler()
|
protected ResourceHandle |
getLibraryHandle(java.lang.String name)
Finds the ResourceHandle object for the native library with the specified name. |
protected ResourceHandle |
getResourceHandle(java.lang.String name)
Finds the ResourceHandle object for the resource with the specified name. |
protected java.util.Enumeration |
getResourceHandles(java.lang.String name)
Returns an Enumeration of ResourceHandle objects representing all of the resources having the specified name. |
java.net.URL[] |
getURLs()
|
Methods inherited from class java.net.URLClassLoader |
definePackage, getPermissions, newInstance, newInstance |
Methods inherited from class java.security.SecureClassLoader |
defineClass |
Methods inherited from class java.lang.ClassLoader |
clearAssertionStatus, defineClass, defineClass, defineClass, definePackage, findLoadedClass, findSystemClass, getPackage, getPackages, getParent, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, loadClass, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public URIClassLoader(java.net.URI[] uris)
uris
- the search pathpublic URIClassLoader(java.net.URI[] uris, java.net.URLStreamHandler jarHandler)
uris
- the search pathjarHandler
- stream handler for JAR files; implements caching policypublic URIClassLoader(java.net.URI[] uris, java.lang.ClassLoader parent)
uris
- the search pathparent
- the parent class loader.public URIClassLoader(java.net.URI[] uris, java.lang.ClassLoader parent, java.net.URLStreamHandler jarHandler)
uris
- the search pathparent
- the parent class loader.jarHandler
- stream handler for JAR files; implements caching policyMethod Detail |
protected void addURI(java.net.URI uri)
uri
- the URI to addprotected void addURL(java.net.URL url)
url
- the URL to addpublic java.net.URL[] getURLs()
protected java.lang.Class findClass(java.lang.String name) throws java.lang.ClassNotFoundException
name
- the name of the class
java.lang.ClassNotFoundException
- if the class could not be foundprotected java.lang.Class defineClass(java.lang.String name, ResourceHandle h) throws java.io.IOException
java.io.IOException
public java.net.URL findResource(java.lang.String name)
name
- the name of the resource
URL
for the resource, or null
if the resource could not be found.public java.util.Enumeration findResources(java.lang.String name) throws java.io.IOException
name
- the resource name
Enumeration
of URL
s
java.io.IOException
- if an I/O exception occursprotected java.lang.String findLibrary(java.lang.String libname)
null
, the VM searches the library along the path
specified as the java.library.path
property.
This method invoke getLibraryHandle(java.lang.String)
method to find handle
of this library. If the handle is found and its URL protocol is "file",
the system-dependent absolute library file path is returned.
Otherwise this method returns null. Subclasses can override this method to provide specific approaches in library searching.
libname
- the library name
System.loadLibrary(java.lang.String)
,
System.mapLibraryName(java.lang.String)
protected ResourceHandle getClassHandle(java.lang.String name)
findClass()
, this method does not load the class.
name
- the name of the class
protected ResourceHandle getResourceHandle(java.lang.String name)
name
- the name of the resource
protected ResourceHandle getLibraryHandle(java.lang.String name)
System.mapLibraryName(String)
method). Next, the
ResourceFinder
is used to look for the library as it
was ordinary resource. Subclasses can override this method to provide specific approaches in library searching.
name
- the name of the library
protected java.util.Enumeration getResourceHandles(java.lang.String name)
name
- the name of the resource
protected java.net.URLStreamHandler getJarHandler()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |