@HashCodeAndEqualsPlugin.Enhance public static class ClassFileLocator.ForClassLoader extends java.lang.Object implements ClassFileLocator
A class file locator that queries a class loader for binary representations of class files.
Important: Even when calling Closeable.close()
on this class file locator, no underlying
class loader is closed if it implements the Closeable
interface as this is typically not intended.
Modifier and Type | Class and Description |
---|---|
protected static class |
ClassFileLocator.ForClassLoader.BootLoaderProxyCreationAction
A privileged action for creating a proxy class loader for the boot class loader.
|
static class |
ClassFileLocator.ForClassLoader.WeaklyReferenced
A class file locator that queries a class loader for binary representations of class files.
|
ClassFileLocator.AgentBased, ClassFileLocator.Compound, ClassFileLocator.ForClassLoader, ClassFileLocator.ForFolder, ClassFileLocator.ForJarFile, ClassFileLocator.ForModule, ClassFileLocator.ForModuleFile, ClassFileLocator.ForUrl, ClassFileLocator.NoOp, ClassFileLocator.PackageDiscriminating, ClassFileLocator.Resolution, ClassFileLocator.Simple
Modifier and Type | Field and Description |
---|---|
private static java.lang.ClassLoader |
BOOT_LOADER_PROXY
A class loader that does not define resources of its own but allows querying for resources supplied by the boot loader.
|
private java.lang.ClassLoader |
classLoader
The class loader to query.
|
CLASS_FILE_EXTENSION
Modifier | Constructor and Description |
---|---|
protected |
ForClassLoader(java.lang.ClassLoader classLoader)
Creates a new class file locator for the given class loader.
|
Modifier and Type | Method and Description |
---|---|
void |
close() |
protected static ClassFileLocator.Resolution |
locate(java.lang.ClassLoader classLoader,
java.lang.String name)
Locates the class file for the supplied type by requesting a resource from the class loader.
|
ClassFileLocator.Resolution |
locate(java.lang.String name)
Locates the class file for a given type and returns the binary data of the class file.
|
static ClassFileLocator |
of(java.lang.ClassLoader classLoader)
Creates a class file locator for a given class loader.
|
static ClassFileLocator |
ofBootLoader()
Creates a class file locator that queries the boot loader.
|
static ClassFileLocator |
ofPlatformLoader()
Creates a class file locator that queries the plaform class loader or the extension class loader if the
current VM is not at least of version 9.
|
static ClassFileLocator |
ofSystemLoader()
Creates a class file locator that queries the system class loader.
|
static java.util.Map<java.lang.Class<?>,byte[]> |
read(java.lang.Class<?>... type)
Attempts to create a binary representation of several loaded types by requesting
data from their respective
ClassLoader s. |
static byte[] |
read(java.lang.Class<?> type)
Attempts to create a binary representation of a loaded type by requesting data from its
ClassLoader . |
static java.util.Map<java.lang.Class<?>,byte[]> |
read(java.util.Collection<? extends java.lang.Class<?>> types)
Attempts to create a binary representation of several loaded types by requesting
data from their respective
ClassLoader s. |
static java.util.Map<java.lang.String,byte[]> |
readToNames(java.lang.Class<?>... type)
Attempts to create a binary representation of several loaded types by requesting
data from their respective
ClassLoader s. |
static java.util.Map<java.lang.String,byte[]> |
readToNames(java.util.Collection<? extends java.lang.Class<?>> types)
Attempts to create a binary representation of several loaded types by requesting
data from their respective
ClassLoader s. |
private static final java.lang.ClassLoader BOOT_LOADER_PROXY
private final java.lang.ClassLoader classLoader
protected ForClassLoader(java.lang.ClassLoader classLoader)
classLoader
- The class loader to query which must not be the bootstrap class loader, i.e. null
.public static ClassFileLocator ofSystemLoader()
public static ClassFileLocator ofPlatformLoader()
public static ClassFileLocator ofBootLoader()
public static ClassFileLocator of(java.lang.ClassLoader classLoader)
classLoader
- The class loader to be used which might be null
to represent the bootstrap loader.public static byte[] read(java.lang.Class<?> type)
ClassLoader
.type
- The type of interest.public static java.util.Map<java.lang.Class<?>,byte[]> read(java.lang.Class<?>... type)
ClassLoader
s.type
- The types of interest.public static java.util.Map<java.lang.Class<?>,byte[]> read(java.util.Collection<? extends java.lang.Class<?>> types)
ClassLoader
s.types
- The types of interest.public static java.util.Map<java.lang.String,byte[]> readToNames(java.lang.Class<?>... type)
ClassLoader
s.type
- The types of interest.public static java.util.Map<java.lang.String,byte[]> readToNames(java.util.Collection<? extends java.lang.Class<?>> types)
ClassLoader
s.types
- The types of interest.public ClassFileLocator.Resolution locate(java.lang.String name) throws java.io.IOException
locate
in interface ClassFileLocator
name
- The name of the type to locate a class file representation for.java.io.IOException
- If reading a class file causes an error.public void close()
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
protected static ClassFileLocator.Resolution locate(java.lang.ClassLoader classLoader, java.lang.String name) throws java.io.IOException
classLoader
- The class loader to query for the resource.name
- The name of the type for which to locate a class file.java.io.IOException
- If reading the class file causes an exception.