public class URIClassLoader extends ExtendedURLClassLoader
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.
Originally written by Dawid Kurzyniec and released to the public domain, as explained at http://creativecommons.org/licenses/publicdomain
Source: http://dcl.mathcs.emory.edu/php/loadPage.php?content=util/features.html#classloading
File.toURL(),
File.toURI()| Constructor and Description |
|---|
URIClassLoader(URI[] uris)
Creates URIClassLoader with the specified search path.
|
URIClassLoader(URI[] uris,
ClassLoader parent)
Creates URIClassLoader with the specified search path and parent class loader.
|
URIClassLoader(URI[] uris,
ClassLoader parent,
URLStreamHandlerFactory handlerFactory)
Creates URIClassLoader with the specified search path and parent class loader.
|
URIClassLoader(URI[] uris,
URLStreamHandlerFactory handlerFactory)
Creates URIClassLoader with the specified search path.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
addURI(URI uri)
Add specified URI at the end of the search path.
|
void |
addURL(URL url)
Add specified URL at the end of the search path.
|
void |
addURLs(List<URL> urls)
Add specified URLs at the end of the search path.
|
protected Class<?> |
defineClass(String name,
edu.emory.mathcs.util.classloader.ResourceHandle h) |
protected Class<?> |
findClass(String name)
Finds and loads the class with the specified name.
|
protected String |
findLibrary(String libname)
Returns the absolute path name of a native library.
|
URL |
findResource(String name)
Finds the resource with the specified name.
|
Enumeration<URL> |
findResources(String name)
Returns an Enumeration of URLs representing all of the resources having the specified name.
|
protected edu.emory.mathcs.util.classloader.ResourceHandle |
getClassHandle(String name)
Finds the ResourceHandle object for the class with the specified name.
|
protected edu.emory.mathcs.util.classloader.ResourceHandle |
getLibraryHandle(String name)
Finds the ResourceHandle object for the native library with the specified name.
|
protected edu.emory.mathcs.util.classloader.ResourceHandle |
getResourceHandle(String name)
Finds the ResourceHandle object for the resource with the specified name.
|
protected Enumeration<edu.emory.mathcs.util.classloader.ResourceHandle> |
getResourceHandles(String name)
Returns an Enumeration of ResourceHandle objects representing all of the resources having the specified name.
|
URL[] |
getURLs() |
close, definePackage, getPermissions, getResourceAsStream, newInstance, newInstancedefineClass, defineClassclearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findLoadedClass, findSystemClass, getClassLoadingLock, getPackage, getPackages, getParent, getResource, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, loadClass, registerAsParallelCapable, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSignerspublic URIClassLoader(URI[] uris)
uris - the search pathpublic URIClassLoader(URI[] uris, URLStreamHandlerFactory handlerFactory)
uris - the search pathhandlerFactory - the URLStreamHandlerFactory to use when creating URLspublic URIClassLoader(URI[] uris, ClassLoader parent)
uris - the search pathparent - the parent class loaderpublic URIClassLoader(URI[] uris, ClassLoader parent, URLStreamHandlerFactory handlerFactory)
uris - the search pathparent - the parent class loader.handlerFactory - the URLStreamHandlerFactory to use when creating URLsprotected void addURI(URI uri)
uri - the URI to addpublic void addURL(URL url)
addURL in class ExtendedURLClassLoaderurl - the URL to addpublic void addURLs(List<URL> urls)
addURLs in class ExtendedURLClassLoaderurls - the URLs to addpublic URL[] getURLs()
getURLs in class URLClassLoaderprotected Class<?> findClass(String name) throws ClassNotFoundException
findClass in class URLClassLoadername - the name of the classClassNotFoundException - if the class could not be foundprotected Class<?> defineClass(String name, edu.emory.mathcs.util.classloader.ResourceHandle h) throws IOException
IOExceptionpublic URL findResource(String name)
findResource in class URLClassLoadername - the name of the resourceURL for the resource, or null if the resource could not be found.public Enumeration<URL> findResources(String name) throws IOException
findResources in class URLClassLoadername - the resource nameEnumeration of URLsIOException - if an I/O exception occursprotected String findLibrary(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.
findLibrary in class ClassLoaderlibname - the library nameSystem.loadLibrary(java.lang.String),
System.mapLibraryName(java.lang.String)protected edu.emory.mathcs.util.classloader.ResourceHandle getClassHandle(String name)
findClass(), this
method does not load the class.name - the name of the classprotected edu.emory.mathcs.util.classloader.ResourceHandle getResourceHandle(String name)
name - the name of the resourceprotected edu.emory.mathcs.util.classloader.ResourceHandle getLibraryHandle(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 libraryprotected Enumeration<edu.emory.mathcs.util.classloader.ResourceHandle> getResourceHandles(String name)
name - the name of the resourceCopyright © 2004–2015 XWiki. All rights reserved.