Package net.bytebuddy.dynamic
Class ClassFileLocator.ForInstrumentation
- java.lang.Object
-
- net.bytebuddy.dynamic.ClassFileLocator.ForInstrumentation
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,ClassFileLocator
- Enclosing interface:
- ClassFileLocator
@Enhance public static class ClassFileLocator.ForInstrumentation extends java.lang.Object implements ClassFileLocator
A Java agent that allows the location of class files by emulating a retransformation. Note that this class file locator causes a class to be loaded in order to look up its class file. Also, this locator does deliberately not support the look-up of classes that represent lambda expressions.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
ClassFileLocator.ForInstrumentation.ClassLoadingDelegate
A delegate that is queried for loading a class.protected static interface
ClassFileLocator.ForInstrumentation.Dispatcher
A dispatcher to interact with theInstrumentation
API.protected static class
ClassFileLocator.ForInstrumentation.ExtractionClassFileTransformer
A non-operational class file transformer that remembers the binary format of a given class.-
Nested classes/interfaces inherited from interface net.bytebuddy.dynamic.ClassFileLocator
ClassFileLocator.Compound, ClassFileLocator.ForClassLoader, ClassFileLocator.ForFolder, ClassFileLocator.ForInstrumentation, ClassFileLocator.ForJarFile, ClassFileLocator.ForModule, ClassFileLocator.ForModuleFile, ClassFileLocator.ForUrl, ClassFileLocator.NoOp, ClassFileLocator.PackageDiscriminating, ClassFileLocator.Resolution, ClassFileLocator.Simple
-
-
Field Summary
Fields Modifier and Type Field Description private ClassFileLocator.ForInstrumentation.ClassLoadingDelegate
classLoadingDelegate
The delegate to load a class by its name.private static ClassFileLocator.ForInstrumentation.Dispatcher
DISPATCHER
A dispatcher for interacting with the instrumentation API.private java.lang.instrument.Instrumentation
instrumentation
The instrumentation instance to use for looking up the binary format of a type.-
Fields inherited from interface net.bytebuddy.dynamic.ClassFileLocator
CLASS_FILE_EXTENSION
-
-
Constructor Summary
Constructors Constructor Description ForInstrumentation(java.lang.instrument.Instrumentation instrumentation, java.lang.ClassLoader classLoader)
Creates an agent-based class file locator.ForInstrumentation(java.lang.instrument.Instrumentation instrumentation, ClassFileLocator.ForInstrumentation.ClassLoadingDelegate classLoadingDelegate)
Creates an agent-based class file locator.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
private static <T> T
doPrivileged(java.security.PrivilegedAction<T> action)
A proxy forjava.security.AccessController#doPrivileged
that is activated if available.static ClassFileLocator
fromInstalledAgent(java.lang.ClassLoader classLoader)
Returns an agent-based class file locator for the given class loader and an already installed Byte Buddy-agent.ClassFileLocator.Resolution
locate(java.lang.String name)
Locates the class file for a given type and returns the binary data of the class file.static ClassFileLocator
of(java.lang.instrument.Instrumentation instrumentation, java.lang.Class<?> type)
Returns a class file locator that is capable of locating a class file for the given type using the given instrumentation instance.private static java.lang.instrument.Instrumentation
resolveByteBuddyAgentInstrumentation()
Resolves the instrumentation provided bynet.bytebuddy.agent.Installer
.
-
-
-
Field Detail
-
DISPATCHER
private static final ClassFileLocator.ForInstrumentation.Dispatcher DISPATCHER
A dispatcher for interacting with the instrumentation API.
-
instrumentation
private final java.lang.instrument.Instrumentation instrumentation
The instrumentation instance to use for looking up the binary format of a type.
-
classLoadingDelegate
private final ClassFileLocator.ForInstrumentation.ClassLoadingDelegate classLoadingDelegate
The delegate to load a class by its name.
-
-
Constructor Detail
-
ForInstrumentation
public ForInstrumentation(java.lang.instrument.Instrumentation instrumentation, @MaybeNull java.lang.ClassLoader classLoader)
Creates an agent-based class file locator.- Parameters:
instrumentation
- The instrumentation to be used.classLoader
- The class loader to read a class from ornull
to use the boot loader.
-
ForInstrumentation
public ForInstrumentation(java.lang.instrument.Instrumentation instrumentation, ClassFileLocator.ForInstrumentation.ClassLoadingDelegate classLoadingDelegate)
Creates an agent-based class file locator.- Parameters:
instrumentation
- The instrumentation to be used.classLoadingDelegate
- The delegate responsible for class loading.
-
-
Method Detail
-
doPrivileged
@Enhance private static <T> T doPrivileged(java.security.PrivilegedAction<T> action)
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.
-
resolveByteBuddyAgentInstrumentation
private static java.lang.instrument.Instrumentation resolveByteBuddyAgentInstrumentation()
Resolves the instrumentation provided bynet.bytebuddy.agent.Installer
.- Returns:
- The installed instrumentation instance.
-
fromInstalledAgent
public static ClassFileLocator fromInstalledAgent(@MaybeNull java.lang.ClassLoader classLoader)
Returns an agent-based class file locator for the given class loader and an already installed Byte Buddy-agent.- Parameters:
classLoader
- The class loader that is expected to load the looked-up a class.- Returns:
- A class file locator for the given class loader based on a Byte Buddy agent.
-
of
public static ClassFileLocator of(java.lang.instrument.Instrumentation instrumentation, java.lang.Class<?> type)
Returns a class file locator that is capable of locating a class file for the given type using the given instrumentation instance.- Parameters:
instrumentation
- The instrumentation instance to query for a retransformation.type
- The locatable type which class loader is used as a fallback.- Returns:
- A class file locator for locating the class file of the given type.
-
locate
public ClassFileLocator.Resolution locate(java.lang.String name)
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.
-
close
public void close()
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
-
-