public class DisposeClassLoader extends URLClassLoader
Modifier and Type | Field and Description |
---|---|
protected File |
loaderDir
Path where resources loaded from JARs will be extracted.
|
Constructor and Description |
---|
DisposeClassLoader() |
DisposeClassLoader(ClassLoader parent) |
Modifier and Type | Method and Description |
---|---|
void |
addJarFile(File file) |
static void |
addTriggerPackage(String pkg) |
protected void |
clearReferences()
Clear references.
|
void |
dispose()
Dispose the class loader.
|
protected boolean |
filter(String name)
Filter classes.
|
Class<?> |
findClass(String name)
Find the specified class in our local repositories, if possible.
|
protected Class<?> |
findClassInternal(String name)
Find specified class in local repositories.
|
protected Class<?> |
findLoadedClass0(String name)
Finds the class with the given name if it has previously been loaded and
cached by this class loader, and return the Class object.
|
protected InputStream |
findLoadedResource(String name)
Finds the resource with the given name if it has previously been loaded
and cached by this class loader, and return an input stream to the
resource data.
|
URL |
findResource(String name)
Find the specified resource in our local repository, and return a
URL refering to it, or null if this resource
cannot be found. |
protected ResourceEntry |
findResourceInternal(String name,
String path)
Find specified resource in local repositories.
|
Enumeration<URL> |
findResources(String name)
Return an enumeration of
URLs |
URL |
getResource(String name)
Find the resource with the given name.
|
InputStream |
getResourceAsStream(String name)
Find the resource with the given name, and return an input stream that
can be used for reading it.
|
protected URL |
getURI(File file)
Get URL.
|
protected URL |
getURL(File file,
boolean encoded)
Get URL.
|
Class<?> |
loadClass(String name)
Load the class with the specified name.
|
Class<?> |
loadClass(String name,
boolean resolve)
Load the class with the specified name, searching using the following
algorithm until it finds and returns the class.
|
protected boolean |
loadedByThisOrChild(Class<? extends Object> clazz)
Determine whether a class was loaded by this class loader or one of its
child class loaders.
|
protected void |
nullInstance(Object instance) |
void |
setWorkDir(File workDir)
Change the work directory.
|
protected boolean |
validate(String name)
Validate a classname.
|
addURL, close, definePackage, getPermissions, getURLs, newInstance, newInstance
defineClass, defineClass
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findSystemClass, getClassLoadingLock, getPackage, getPackages, getParent, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, registerAsParallelCapable, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
protected File loaderDir
public DisposeClassLoader()
public DisposeClassLoader(ClassLoader parent)
public static void addTriggerPackage(String pkg)
public void addJarFile(File file)
public void setWorkDir(File workDir)
public void dispose()
protected void clearReferences()
protected void nullInstance(Object instance)
protected boolean loadedByThisOrChild(Class<? extends Object> clazz)
public URL getResource(String name)
null
.
This method searches according to the following algorithm, returning as
soon as it finds the appropriate URL. If the resource cannot be found,
returns null
.
delegate
property is set to true
,
call the getResource()
method of the parent class loader, if
any.findResource()
to find this resource in our locally
defined repositories.getResource()
method of the parent class
loader, if any.getResource
in class ClassLoader
name
- Name of the resource to return a URL forpublic InputStream getResourceAsStream(String name)
getResource()
, after checking to see if the resource data
has been previously cached. If the resource cannot be found, return
null
.getResourceAsStream
in class URLClassLoader
name
- Name of the resource to return an input stream forprotected InputStream findLoadedResource(String name)
null
.name
- Name of the resource to returnpublic URL findResource(String name)
URL
refering to it, or null
if this resource
cannot be found.findResource
in class URLClassLoader
name
- Name of the resource to be foundpublic Enumeration<URL> findResources(String name) throws IOException
URLs representing all of
the resources with the given name. If no resources with this
name are found, return an empty set.
findResources
in class URLClassLoader
name
- Name of the resources to be foundIOException
- if an input/output error occursprotected ResourceEntry findResourceInternal(String name, String path)
protected URL getURL(File file, boolean encoded) throws MalformedURLException
MalformedURLException
protected URL getURI(File file) throws MalformedURLException
MalformedURLException
public Class<?> loadClass(String name) throws ClassNotFoundException
loadClass(String, boolean)
with
false
as the second argument.loadClass
in class ClassLoader
name
- Name of the class to be loadedClassNotFoundException
- if the class was not foundpublic Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException
ClassNotFoundException
.
findLoadedClass(String)
to check if the class has
already been loaded. If it has, the same Class
object is
returned.delegate
property is set to true
,
call the loadClass()
method of the parent class loader, if
any.findClass()
to find this class in our locally
defined repositories.loadClass()
method of our parent class loader,
if any.resolve
flag is true
, this method will then
call resolveClass(Class)
on the resulting Class object.loadClass
in class ClassLoader
name
- Name of the class to be loadedresolve
- If true
then resolve the classClassNotFoundException
- if the class was not foundprotected Class<?> findLoadedClass0(String name)
null
.name
- Name of the resource to returnpublic Class<?> findClass(String name) throws ClassNotFoundException
ClassNotFoundException
.findClass
in class URLClassLoader
name
- Name of the class to be loadedClassNotFoundException
- if the class was not foundprotected Class<?> findClassInternal(String name) throws ClassNotFoundException
ClassNotFoundException
protected boolean validate(String name)
name
- class nameprotected boolean filter(String name)
name
- class nameCopyright © 2017. All rights reserved.