Package net.bytebuddy.dynamic
Class ClassFileLocator.ForClassLoader
- java.lang.Object
-
- net.bytebuddy.dynamic.ClassFileLocator.ForClassLoader
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,ClassFileLocator
- Enclosing interface:
- ClassFileLocator
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 theCloseable
interface as this is typically not intended.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ClassFileLocator.ForClassLoader.WeaklyReferenced
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.AgentBased, ClassFileLocator.Compound, ClassFileLocator.ForClassLoader, ClassFileLocator.ForFolder, ClassFileLocator.ForJarFile, ClassFileLocator.ForModule, ClassFileLocator.ForModuleFile, ClassFileLocator.NoOp, ClassFileLocator.PackageDiscriminating, ClassFileLocator.Resolution, ClassFileLocator.Simple
-
-
Field Summary
-
Fields inherited from interface net.bytebuddy.dynamic.ClassFileLocator
CLASS_FILE_EXTENSION
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
ForClassLoader(java.lang.ClassLoader classLoader)
Creates a new class file locator for the given class loader.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
protected static ClassFileLocator.Resolution
locate(java.lang.ClassLoader classLoader, java.lang.String typeName)
Locates the class file for the supplied type by requesting a resource from the class loader.ClassFileLocator.Resolution
locate(java.lang.String typeName)
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
ofClassPath()
Creates a class file locator that queries the system class loader.static ClassFileLocator.Resolution
read(java.lang.Class<?> type)
Attempts to create a binary representation of a loaded type by requesting data from itsClassLoader
.
-
-
-
Method Detail
-
ofClassPath
public static ClassFileLocator ofClassPath()
Creates a class file locator that queries the system class loader.- Returns:
- A class file locator that queries the system class loader.
-
of
public static ClassFileLocator of(java.lang.ClassLoader classLoader)
Creates a class file locator for a given class loader.- Parameters:
classLoader
- The class loader to be used. If this class loader represents the bootstrap class loader which is represented by thenull
value, this system class loader is used instead.- Returns:
- A corresponding source locator.
-
read
public static ClassFileLocator.Resolution read(java.lang.Class<?> type)
Attempts to create a binary representation of a loaded type by requesting data from itsClassLoader
.- Parameters:
type
- The type of interest.- Returns:
- The binary data to this type which might be illegal.
-
locate
public ClassFileLocator.Resolution locate(java.lang.String typeName) throws java.io.IOException
Description copied from interface:ClassFileLocator
Locates the class file for a given type and returns the binary data of the class file.- Specified by:
locate
in interfaceClassFileLocator
- Parameters:
typeName
- The name of the type to locate a class file representation for.- Returns:
- Any binary representation of the type which might be illegal.
- Throws:
java.io.IOException
- If reading a class file causes an error.
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Throws:
java.io.IOException
-
locate
protected static ClassFileLocator.Resolution locate(java.lang.ClassLoader classLoader, java.lang.String typeName) throws java.io.IOException
Locates the class file for the supplied type by requesting a resource from the class loader.- Parameters:
classLoader
- The class loader to query for the resource.typeName
- The name of the type for which to locate a class file.- Returns:
- A resolution for the class file.
- Throws:
java.io.IOException
- If reading the class file causes an exception.
-
-