Package net.bytebuddy.dynamic.loading
Interface ClassInjector
-
- All Known Implementing Classes:
ClassInjector.AbstractBase,ClassInjector.UsingInstrumentation,ClassInjector.UsingJna,ClassInjector.UsingLookup,ClassInjector.UsingReflection,ClassInjector.UsingUnsafe
public interface ClassInjectorA class injector is capable of injecting classes into a
ClassLoaderwithout requiring the class loader to being able to explicitly look up these classes.Important: Byte Buddy does not supply privileges when injecting code. When using a
java.lang.SecurityManager, the user of this injector is responsible for providing access to non-public properties.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classClassInjector.AbstractBaseAn abstract base implementation of a class injector.static classClassInjector.UsingInstrumentationA class injector using aInstrumentationto append to either the boot classpath or the system class path.static classClassInjector.UsingJnaA class injector using JNA to invoke JNI's define class utility for defining a class.static classClassInjector.UsingLookupA class injector that uses ajava.lang.invoke.MethodHandles$Lookupobject for defining a class.static classClassInjector.UsingReflectionA class injector that uses reflective method calls.static classClassInjector.UsingUnsafeA class injector that usessun.misc.Unsafeorjdk.internal.misc.Unsafeto inject classes.
-
Field Summary
Fields Modifier and Type Field Description static booleanALLOW_EXISTING_TYPESDetermines the default behavior for type injections when a type is already loaded.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.util.Map<TypeDescription,java.lang.Class<?>>inject(java.util.Map<? extends TypeDescription,byte[]> types)Injects the given types into the represented class loader.java.util.Map<TypeDescription,java.lang.Class<?>>inject(java.util.Set<? extends TypeDescription> types, ClassFileLocator classFileLocator)Injects the given types into the represented class loader.java.util.Map<java.lang.String,java.lang.Class<?>>injectRaw(java.util.Map<java.lang.String,byte[]> types)Injects the given types into the represented class loader.java.util.Map<java.lang.String,java.lang.Class<?>>injectRaw(java.util.Set<java.lang.String> names, ClassFileLocator classFileLocator)Injects the given types into the represented class loader.booleanisAlive()Indicates if this class injector is available on the current VM.
-
-
-
Field Detail
-
ALLOW_EXISTING_TYPES
static final boolean ALLOW_EXISTING_TYPES
Determines the default behavior for type injections when a type is already loaded.- See Also:
- Constant Field Values
-
-
Method Detail
-
isAlive
boolean isAlive()
Indicates if this class injector is available on the current VM.- Returns:
trueif this injector is available on the current VM.
-
inject
java.util.Map<TypeDescription,java.lang.Class<?>> inject(java.util.Set<? extends TypeDescription> types, ClassFileLocator classFileLocator)
Injects the given types into the represented class loader.- Parameters:
types- The types to load via injection.classFileLocator- The class file locator to use for resolving binary representations.- Returns:
- The loaded types that were passed as arguments.
-
injectRaw
java.util.Map<java.lang.String,java.lang.Class<?>> injectRaw(java.util.Set<java.lang.String> names, ClassFileLocator classFileLocator)Injects the given types into the represented class loader.- Parameters:
names- The names of the types to load via injection.classFileLocator- The class file locator to use for resolving binary representations.- Returns:
- The loaded types that were passed as arguments.
-
inject
java.util.Map<TypeDescription,java.lang.Class<?>> inject(java.util.Map<? extends TypeDescription,byte[]> types)
Injects the given types into the represented class loader.- Parameters:
types- The types to load via injection.- Returns:
- The loaded types that were passed as arguments.
-
injectRaw
java.util.Map<java.lang.String,java.lang.Class<?>> injectRaw(java.util.Map<java.lang.String,byte[]> types)
Injects the given types into the represented class loader.- Parameters:
types- The names of the type to load via injection.- Returns:
- The loaded types that were passed as arguments.
-
-