Package net.bytebuddy.dynamic
Class ClassFileLocator.ForClassLoader
java.lang.Object
net.bytebuddy.dynamic.ClassFileLocator.ForClassLoader
- All Implemented Interfaces:
Closeable
,AutoCloseable
,ClassFileLocator
- Enclosing interface:
ClassFileLocator
@Enhance
public static class ClassFileLocator.ForClassLoader
extends 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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static enum
A privileged action for creating a proxy class loader for the boot class loader.static class
A class file locator that queries a class loader for binary representations of class files.Nested classes/interfaces inherited from interface net.bytebuddy.dynamic.ClassFileLocator
ClassFileLocator.Compound, ClassFileLocator.Filtering, ClassFileLocator.ForClassLoader, ClassFileLocator.ForFolder, ClassFileLocator.ForInstrumentation, ClassFileLocator.ForJarFile, ClassFileLocator.ForModule, ClassFileLocator.ForModuleFile, ClassFileLocator.ForUrl, ClassFileLocator.MultiReleaseAware, ClassFileLocator.NoOp, ClassFileLocator.PackageDiscriminating, ClassFileLocator.Resolution, ClassFileLocator.Simple
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final ClassLoader
A class loader that does not define resources of its own but allows querying for resources supplied by the boot loader.private final ClassLoader
The class loader to query.Fields inherited from interface net.bytebuddy.dynamic.ClassFileLocator
CLASS_FILE_EXTENSION, META_INF_VERSIONS
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
ForClassLoader
(ClassLoader classLoader) Creates a new class file locator for the given class loader. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
private static <T> T
doPrivileged
(PrivilegedAction<T> action) A proxy forjava.security.AccessController#doPrivileged
that is activated if available.protected static ClassFileLocator.Resolution
locate
(ClassLoader classLoader, String name) Locates the class file for the supplied type by requesting a resource from the class loader.Locates the class file for a given type and returns the binary data of the class file.static ClassFileLocator
of
(ClassLoader classLoader) Creates a class file locator for a given class loader.static ClassFileLocator
Creates a class file locator that queries the boot loader.static ClassFileLocator
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
Creates a class file locator that queries the system class loader.static byte[]
Attempts to create a binary representation of a loaded type by requesting data from itsClassLoader
.Attempts to create a binary representation of several loaded types by requesting data from their respectiveClassLoader
s.read
(Collection<? extends Class<?>> types) Attempts to create a binary representation of several loaded types by requesting data from their respectiveClassLoader
s.readToNames
(Class<?>... type) Attempts to create a binary representation of several loaded types by requesting data from their respectiveClassLoader
s.readToNames
(Collection<? extends Class<?>> types) Attempts to create a binary representation of several loaded types by requesting data from their respectiveClassLoader
s.
-
Field Details
-
BOOT_LOADER_PROXY
A class loader that does not define resources of its own but allows querying for resources supplied by the boot loader. -
classLoader
The class loader to query.
-
-
Constructor Details
-
ForClassLoader
Creates a new class file locator for the given class loader.- Parameters:
classLoader
- The class loader to query which must not be the bootstrap class loader, i.e.null
.
-
-
Method Details
-
doPrivileged
A proxy forjava.security.AccessController#doPrivileged
that is activated if available.- Type Parameters:
T
- The type of the action's resolved value.- Parameters:
action
- The action to execute from a privileged context.- Returns:
- The action's resolved value.
-
ofSystemLoader
Creates a class file locator that queries the system class loader.- Returns:
- A class file locator that queries the system class loader.
-
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.- Returns:
- A class file locator that queries the plaform class loader or the extension class loader.
-
ofBootLoader
Creates a class file locator that queries the boot loader.- Returns:
- A class file locator that queries the boot loader.
-
of
Creates a class file locator for a given class loader.- Parameters:
classLoader
- The class loader to be used which might benull
to represent the bootstrap loader.- Returns:
- A corresponding source locator.
-
read
Attempts to create a binary representation of a loaded type by requesting data from itsClassLoader
.- Parameters:
type
- The type of interest.- Returns:
- The binary representation of the supplied type.
-
read
Attempts to create a binary representation of several loaded types by requesting data from their respectiveClassLoader
s.- Parameters:
type
- The types of interest.- Returns:
- A mapping of the supplied types to their binary representation.
-
read
Attempts to create a binary representation of several loaded types by requesting data from their respectiveClassLoader
s.- Parameters:
types
- The types of interest.- Returns:
- A mapping of the supplied types to their binary representation.
-
readToNames
Attempts to create a binary representation of several loaded types by requesting data from their respectiveClassLoader
s.- Parameters:
type
- The types of interest.- Returns:
- A mapping of the supplied types' names to their binary representation.
-
readToNames
Attempts to create a binary representation of several loaded types by requesting data from their respectiveClassLoader
s.- Parameters:
types
- The types of interest.- Returns:
- A mapping of the supplied types' names to their binary representation.
-
locate
Locates the class file for a given type and returns the binary data of the class file.- Specified by:
locate
in interfaceClassFileLocator
- Parameters:
name
- The name of the type to locate a class file representation for.- Returns:
- Any binary representation of the type which might be illegal.
- Throws:
IOException
- If reading a class file causes an error.
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
locate
protected static ClassFileLocator.Resolution locate(ClassLoader classLoader, String name) throws IOException Locates the class file for the supplied type by requesting a resource from the class loader.- Parameters:
classLoader
- The class loader to query.name
- The name of the type for which to locate a class file.- Returns:
- A resolution for the class file.
- Throws:
IOException
- If reading the class file causes an exception.
-