Package net.bytebuddy.dynamic.loading
Class InjectionClassLoader
- java.lang.Object
-
- java.lang.ClassLoader
-
- net.bytebuddy.dynamic.loading.InjectionClassLoader
-
- Direct Known Subclasses:
ByteArrayClassLoader,MultipleParentClassLoader
public abstract class InjectionClassLoader extends java.lang.ClassLoaderAn injection class loader allows for the injection of a class after the class loader was created. Injection is only possible if this class loader is not sealed.
Important: Not sealing a class loader allows to break package encapsulation for anybody getting hold of a reference to this class loader.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classInjectionClassLoader.StrategyA class loading strategy for adding a type to an injection class loader.
-
Field Summary
Fields Modifier and Type Field Description private booleansealedIndicates if this class loader is sealed, i.e.
-
Constructor Summary
Constructors Modifier Constructor Description protectedInjectionClassLoader(java.lang.ClassLoader parent, boolean sealed)Creates a new injection class loader.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description java.lang.Class<?>defineClass(java.lang.String name, byte[] binaryRepresentation)Defines a new type to be loaded by this class loader.java.util.Map<java.lang.String,java.lang.Class<?>>defineClasses(java.util.Map<java.lang.String,byte[]> typeDefinitions)Defines a group of types to be loaded by this class loader.protected abstract java.util.Map<java.lang.String,java.lang.Class<?>>doDefineClasses(java.util.Map<java.lang.String,byte[]> typeDefinitions)Defines a group of types to be loaded by this class loader.booleanisSealed()Returnstrueif this class loader is sealed.-
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findClass, findLibrary, findLoadedClass, findResource, findResource, findResources, findSystemClass, getClassLoadingLock, getDefinedPackage, getDefinedPackages, getName, getPackage, getPackages, getParent, getPlatformClassLoader, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, loadClass, loadClass, registerAsParallelCapable, resolveClass, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
-
-
-
-
Method Detail
-
isSealed
public boolean isSealed()
Returnstrueif this class loader is sealed.- Returns:
trueif this class loader is sealed.
-
defineClass
public java.lang.Class<?> defineClass(java.lang.String name, byte[] binaryRepresentation) throws java.lang.ClassNotFoundExceptionDefines a new type to be loaded by this class loader.- Parameters:
name- The name of the type.binaryRepresentation- The type's binary representation.- Returns:
- The defined class or a previously defined class.
- Throws:
java.lang.ClassNotFoundException- If the class could not be loaded.
-
defineClasses
public java.util.Map<java.lang.String,java.lang.Class<?>> defineClasses(java.util.Map<java.lang.String,byte[]> typeDefinitions) throws java.lang.ClassNotFoundExceptionDefines a group of types to be loaded by this class loader. If this class loader is sealed, anIllegalStateExceptionis thrown.- Parameters:
typeDefinitions- The types binary representations.- Returns:
- The mapping of defined classes or previously defined classes by their name.
- Throws:
java.lang.ClassNotFoundException- If the class could not be loaded.
-
doDefineClasses
protected abstract java.util.Map<java.lang.String,java.lang.Class<?>> doDefineClasses(java.util.Map<java.lang.String,byte[]> typeDefinitions) throws java.lang.ClassNotFoundExceptionDefines a group of types to be loaded by this class loader.- Parameters:
typeDefinitions- The types binary representations.- Returns:
- The mapping of defined classes or previously defined classes by their name.
- Throws:
java.lang.ClassNotFoundException- If the class could not be loaded.
-
-