saker.util Documentation TaskDoc JavaDoc Packages
public class MultiDataClassLoader extends ClassLoader
ClassLoader implementation that uses ClassLoaderDataFinder instances to locate the classes and resources.

This classloader can be used when the resources for the to be loaded classes can be retrieved from one or multiple ClassLoaderDataFinder instance(s).

Users should keep track of the data finders which are used to construct a classloader and manually close them later, when the classloader is no longer used. It's also possible to keep a PhantomReference to the classloader instance, and when the classloader is garbage collected, close the data finders. It requires more implementational code, or maybe use the Cleaner class, but that is only available from JRE9+.

When a resource retrieval is requested from the classloader, it will iterate through the data finders registered in it, and return the first match that is found for the resource. The data finders are iterated in the order as it was specified during initialization.

The classloader doesn't implement the ClassLoader.findLibrary(String) function. It should be overridden by subclasses if they need it.

Constructors
public
Creates a new instance.
public
Creates a new instance.
public
Creates a new instance.
public
Creates a new instance.
Methods
protected Class<?>
Finds the class with the specified binary name.
protected URL
Finds the resource with the given name.
protected Enumeration<URL>
Returns an enumeration of URL objects representing all the resources with the given name.
public Collection<ClassLoaderDataFinder>
Gets the data finders which are used by this classloader.
protected ProtectionDomain
Gets the protection domain that should be used when defining a class.
public InputStream
Returns an input stream for reading the specified resource.
public String
Returns a string representation of the object.
Creates a new instance.

Duplicates are removed from the argument data finders.

parentThe parent classloader to use. This argument is delegated to the super constructor.
datafindersThe data finders to use.
NullPointerExceptionIf the datafinders iterable or any of its elements are null.
Creates a new instance.

Duplicates are removed from the argument data finders.

parentThe parent classloader to use. This argument is delegated to the super constructor.
datafindersThe data finders to use.
NullPointerExceptionIf the datafinders array or any of its elements are null.
Creates a new instance.

Duplicates are removed from the argument data finders.

datafindersThe data finders to use.
NullPointerExceptionIf the datafinders iterable or any of its elements are null.
Creates a new instance.

Duplicates are removed from the argument data finders.

datafindersThe data finders to use.
NullPointerExceptionIf the datafinders array or any of its elements are null.
protected Class<?> findClass(String name) throws ClassNotFoundException
Overridden from: ClassLoader
Finds the class with the specified binary name. This method should be overridden by class loader implementations that follow the delegation model for loading classes, and will be invoked by the loadClass method after checking the parent class loader for the requested class. The default implementation throws a ClassNotFoundException.
nameThe binary name of the class
The resulting Class object
ClassNotFoundExceptionIf the class could not be found
1.2
protected URL findResource(String name)
Overridden from: ClassLoader
Finds the resource with the given name. Class loader implementations should override this method to specify where to find resources.
nameThe resource name
A URL object for reading the resource, or null if the resource could not be found
1.2
Overridden from: ClassLoader
Returns an enumeration of URL objects representing all the resources with the given name. Class loader implementations should override this method to specify where to load resources from.
nameThe resource name
An enumeration of URL objects for the resources
IOExceptionIf I/O errors occur
1.2
Gets the data finders which are used by this classloader.
An unmodifiable collection of data finders.
Gets the protection domain that should be used when defining a class.

This method can be overridden by subclasses to provide a ProtectionDomain to use when defining a class.

The default implementation returns null.

datafinderThe data finder that was used to retrieve the class bytes.
nameThe name of the class to define.
The protection domain to use, may be null.
Overridden from: ClassLoader
Returns an input stream for reading the specified resource.

The search order is described in the documentation for ClassLoader.getResource(String).

nameThe resource name
An input stream for reading the resource, or null if the resource could not be found
1.1
public String toString()
Overridden from: Object
Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.

The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:

 getClass().getName() + '@' + Integer.toHexString(hashCode())
 
a string representation of the object.