Package net.bytebuddy.dynamic
Class ClassFileLocator.ForModule
java.lang.Object
net.bytebuddy.dynamic.ClassFileLocator.ForModule
- All Implemented Interfaces:
Closeable
,AutoCloseable
,ClassFileLocator
- Enclosing interface:
ClassFileLocator
A class file locator that locates class files by querying a Java module's getResourceAsStream
method.
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 TypeClassDescriptionstatic class
A class file locator for a Java module that only references this module weakly.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 final JavaModule
The represented Java module.private static final Object[]
An empty array that can be used to indicate no arguments to avoid an allocation on a reflective call.Fields inherited from interface net.bytebuddy.dynamic.ClassFileLocator
CLASS_FILE_EXTENSION, META_INF_VERSIONS
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
ForModule
(JavaModule module) Creates a new class file locator for a Java module. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Locates the class file for a given type and returns the binary data of the class file.protected static ClassFileLocator.Resolution
locate
(JavaModule module, String typeName) Creates a resolution for a Java module's class files.static ClassFileLocator
of
(JavaModule module) Returns a class file locator for the provided module.static ClassFileLocator
Returns a class file locator that exposes all class files of the boot module layer.
-
Field Details
-
NO_ARGUMENT
An empty array that can be used to indicate no arguments to avoid an allocation on a reflective call. -
module
The represented Java module.
-
-
Constructor Details
-
ForModule
Creates a new class file locator for a Java module.- Parameters:
module
- The represented Java module.
-
-
Method Details
-
ofBootLayer
Returns a class file locator that exposes all class files of the boot module layer. This class file locator is only available on virtual machines of version 9 or later. On earlier versions, the returned class file locator does not locate any resources.- Returns:
- A class file locator that locates classes of the boot layer.
-
of
Returns a class file locator for the provided module. If the provided module is not named, class files are located via this unnamed module's class loader.- Parameters:
module
- The module to create a class file locator for.- Returns:
- An appropriate class file locator.
-
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.
-
locate
protected static ClassFileLocator.Resolution locate(JavaModule module, String typeName) throws IOException Creates a resolution for a Java module's class files.- Parameters:
module
- The Java module to query.typeName
- The name of the type being queried.- Returns:
- A resolution for the query.
- Throws:
IOException
- If an I/O exception was thrown.
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-