Package net.bytebuddy.dynamic
Class ClassFileLocator.ForModule
- java.lang.Object
-
- net.bytebuddy.dynamic.ClassFileLocator.ForModule
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,ClassFileLocator
- Enclosing interface:
- ClassFileLocator
@Enhance public static class ClassFileLocator.ForModule extends java.lang.Object implements ClassFileLocator
A class file locator that locates class files by querying a Java module's
getResourceAsStreammethod.Important: Even when calling
Closeable.close()on this class file locator, no underlying class loader is closed if it implements theCloseableinterface as this is typically not intended.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classClassFileLocator.ForModule.WeaklyReferencedA 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
Fields Modifier and Type Field Description private JavaModulemoduleThe represented Java module.private static java.lang.Object[]NO_ARGUMENTAn 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
Constructors Modifier Constructor Description protectedForModule(JavaModule module)Creates a new class file locator for a Java module.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()ClassFileLocator.Resolutionlocate(java.lang.String name)Locates the class file for a given type and returns the binary data of the class file.protected static ClassFileLocator.Resolutionlocate(JavaModule module, java.lang.String typeName)Creates a resolution for a Java module's class files.static ClassFileLocatorof(JavaModule module)Returns a class file locator for the provided module.static ClassFileLocatorofBootLayer()Returns a class file locator that exposes all class files of the boot module layer.
-
-
-
Field Detail
-
NO_ARGUMENT
private static final java.lang.Object[] NO_ARGUMENT
An empty array that can be used to indicate no arguments to avoid an allocation on a reflective call.
-
module
private final JavaModule module
The represented Java module.
-
-
Constructor Detail
-
ForModule
protected ForModule(JavaModule module)
Creates a new class file locator for a Java module.- Parameters:
module- The represented Java module.
-
-
Method Detail
-
ofBootLayer
public static ClassFileLocator 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
public static ClassFileLocator of(JavaModule module)
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
public ClassFileLocator.Resolution locate(java.lang.String name) throws java.io.IOException
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:
java.io.IOException- If reading a class file causes an error.
-
locate
protected static ClassFileLocator.Resolution locate(JavaModule module, java.lang.String typeName) throws java.io.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:
java.io.IOException- If an I/O exception was thrown.
-
close
public void close()
- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable
-
-