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 enumA privileged action for creating a proxy class loader for the boot class loader.static classA class file locator that queries a class loader for binary representations of class files.Nested classes/interfaces inherited from interface 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
Fields inherited from interface ClassFileLocator
CLASS_FILE_EXTENSION, META_INF_VERSIONS -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedForClassLoader(ClassLoader classLoader) Creates a new class file locator for the given class loader. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()protected static ClassFileLocator.Resolutionlocate(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 ClassFileLocatorof(ClassLoader classLoader) Creates a class file locator for a given class loader.static ClassFileLocatorCreates a class file locator that queries the boot loader.static ClassFileLocatorCreates 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 ClassFileLocatorCreates 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 respectiveClassLoaders.read(Collection<? extends Class<?>> types) Attempts to create a binary representation of several loaded types by requesting data from their respectiveClassLoaders.readToNames(Class<?>... type) Attempts to create a binary representation of several loaded types by requesting data from their respectiveClassLoaders.readToNames(Collection<? extends Class<?>> types) Attempts to create a binary representation of several loaded types by requesting data from their respectiveClassLoaders.
-
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
-
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 benullto 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 respectiveClassLoaders.- 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 respectiveClassLoaders.- 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 respectiveClassLoaders.- 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 respectiveClassLoaders.- 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:
locatein 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:
closein interfaceAutoCloseable- Specified by:
closein 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.
-