Class DynamicType.AbstractBase
- java.lang.Object
-
- net.bytebuddy.dynamic.DynamicType.AbstractBase
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,ClassFileLocator,DynamicType
- Direct Known Subclasses:
AgentBuilder.Transformer.ForAdvice.LazyDynamicType,DynamicType.Default
- Enclosing interface:
- DynamicType
@Enhance public abstract static class DynamicType.AbstractBase extends java.lang.Object implements DynamicType
-
-
Nested Class Summary
-
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
-
Nested classes/interfaces inherited from interface net.bytebuddy.dynamic.DynamicType
DynamicType.AbstractBase, DynamicType.Builder<T>, DynamicType.Default, DynamicType.Loaded<T>, DynamicType.Unloaded<T>
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.StringMANIFEST_VERSIONThe default version of a jar file manifest.private static java.lang.StringTEMP_SUFFIXA suffix for temporary files.-
Fields inherited from interface net.bytebuddy.dynamic.ClassFileLocator
CLASS_FILE_EXTENSION, META_INF_VERSIONS
-
-
Constructor Summary
Constructors Constructor Description AbstractBase()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()private java.io.FiledoInject(java.io.File sourceJar, java.io.File targetJar)Injects this dynamic type into a source jar and writes the result to the target jar.java.util.Set<TypeDescription>getAllTypeDescriptions()Returns a set of all types that are represented by this dynamic type.java.util.Map<TypeDescription,byte[]>getAllTypes()Returns all types that are implied by this dynamic type.java.util.Set<TypeDescription>getAuxiliaryTypeDescriptions()Returns a set of all auxiliary types that are represented by this dynamic type.java.util.Map<TypeDescription,byte[]>getAuxiliaryTypes()Returns a map of all auxiliary types that are required for making use of the main type.java.util.Map<TypeDescription,LoadedTypeInitializer>getLoadedTypeInitializers()Returns a map of all loaded type initializers for the main type and all auxiliary types, if any.booleanhasAliveLoadedTypeInitializers()Checks if a dynamic type requires some form of explicit type initialization, either for itself or for one of its auxiliary types, if any.java.io.Fileinject(java.io.File jar)Injects the types of this dynamic type into a given jar file.java.io.Fileinject(java.io.File sourceJar, java.io.File targetJar)Injects the types of this dynamic type into a given jar file.ClassFileLocator.Resolutionlocate(java.lang.String name)Locates the class file for a given type and returns the binary data of the class file.java.util.Map<TypeDescription,java.io.File>saveIn(java.io.File folder)Saves a dynamic type in a given folder using the Java class file format while respecting the naming conventions for saving compiled Java classes.java.io.FiletoJar(java.io.File file)Saves the contents of this dynamic type inside a jar file.java.io.FiletoJar(java.io.File file, java.util.jar.Manifest manifest)Saves the contents of this dynamic type inside a jar file.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface net.bytebuddy.dynamic.DynamicType
getAuxiliaries, getBytes, getLoadedTypeInitializer, getTypeDescription
-
-
-
-
Field Detail
-
MANIFEST_VERSION
private static final java.lang.String MANIFEST_VERSION
The default version of a jar file manifest.- See Also:
- Constant Field Values
-
TEMP_SUFFIX
private static final java.lang.String TEMP_SUFFIX
A suffix for temporary files.- See Also:
- Constant Field Values
-
-
Method Detail
-
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.
-
close
public void close()
- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein interfaceDynamicType
-
getAuxiliaryTypeDescriptions
public java.util.Set<TypeDescription> getAuxiliaryTypeDescriptions()
Returns a set of all auxiliary types that are represented by this dynamic type.- Specified by:
getAuxiliaryTypeDescriptionsin interfaceDynamicType- Returns:
- A set of all auxiliary types.
-
getAllTypeDescriptions
public java.util.Set<TypeDescription> getAllTypeDescriptions()
Returns a set of all types that are represented by this dynamic type.- Specified by:
getAllTypeDescriptionsin interfaceDynamicType- Returns:
- A set of all represented types.
-
getAllTypes
public java.util.Map<TypeDescription,byte[]> getAllTypes()
Returns all types that are implied by this dynamic type.- Specified by:
getAllTypesin interfaceDynamicType- Returns:
- A mapping from all type descriptions, the actual type and its auxiliary types to their binary representation
-
getLoadedTypeInitializers
public java.util.Map<TypeDescription,LoadedTypeInitializer> getLoadedTypeInitializers()
Returns a map of all loaded type initializers for the main type and all auxiliary types, if any.
Note: The type descriptions will most likely differ from the binary representation of this type. Normally, annotations and intercepted methods are not added to the type descriptions of auxiliary types.
- Specified by:
getLoadedTypeInitializersin interfaceDynamicType- Returns:
- A mapping of all types' descriptions to their loaded type initializers.
-
hasAliveLoadedTypeInitializers
public boolean hasAliveLoadedTypeInitializers()
Checks if a dynamic type requires some form of explicit type initialization, either for itself or for one of its auxiliary types, if any. This is the case when this dynamic type was defined to delegate method calls to a specific instance which is stored in a field of the created type. If this class serialized, it could not be used without its loaded type initializers since the field value represents a specific runtime context.- Specified by:
hasAliveLoadedTypeInitializersin interfaceDynamicType- Returns:
trueif this type requires explicit type initialization.
-
getAuxiliaryTypes
public java.util.Map<TypeDescription,byte[]> getAuxiliaryTypes()
Returns a map of all auxiliary types that are required for making use of the main type.
Note: The type descriptions will most likely differ from the binary representation of this type. Normally, annotations and intercepted methods are not added to the type descriptions of auxiliary types.
- Specified by:
getAuxiliaryTypesin interfaceDynamicType- Returns:
- A map of all auxiliary types by their descriptions to their binary representation.
-
saveIn
public java.util.Map<TypeDescription,java.io.File> saveIn(java.io.File folder) throws java.io.IOException
Saves a dynamic type in a given folder using the Java class file format while respecting the naming conventions for saving compiled Java classes. All auxiliary types, if any, are saved in the same directory. The resulting folder structure will resemble the structure that is required for Java run times, i.e. each folder representing a segment of the package name. If the specified
folderdoes not yet exist, it is created during the call of this method.Note: The type descriptions will most likely differ from the binary representation of this type. Normally, annotations and intercepted methods are not added to the type descriptions of auxiliary types.
- Specified by:
saveInin interfaceDynamicType- Parameters:
folder- The base target folder for storing this dynamic type and its auxiliary types, if any.- Returns:
- A map of type descriptions pointing to files with their stored binary representations within
folder. - Throws:
java.io.IOException- Thrown if the underlying file operations cause anIOException.
-
inject
public java.io.File inject(java.io.File sourceJar, java.io.File targetJar) throws java.io.IOExceptionInjects the types of this dynamic type into a given jar file. Any pre-existent type with the same name is overridden during injection. The resulting jar is going to be a recreation of the original jar and not a patched version with a new central directory. No directory entries are added to the generated jar.- Specified by:
injectin interfaceDynamicType- Parameters:
sourceJar- The original jar file.targetJar- Thesourcejar file with the injected contents.- Returns:
- The
targetjar file. - Throws:
java.io.IOException- If an I/O exception occurs while injecting from the source into the target.
-
inject
public java.io.File inject(java.io.File jar) throws java.io.IOExceptionInjects the types of this dynamic type into a given jar file. Any pre-existent type with the same name is overridden during injection. The resulting jar is going to be a recreation of the original jar and not a patched version with a new central directory. No directory entries are added to the generated jar.- Specified by:
injectin interfaceDynamicType- Parameters:
jar- The jar file to replace with an injected version.- Returns:
- The
jarfile. - Throws:
java.io.IOException- If an I/O exception occurs while injecting into the jar.
-
doInject
private java.io.File doInject(java.io.File sourceJar, java.io.File targetJar) throws java.io.IOExceptionInjects this dynamic type into a source jar and writes the result to the target jar.- Parameters:
sourceJar- The source jar.targetJar- The target jar.- Returns:
- The jar file that was written to.
- Throws:
java.io.IOException- If an I/O error occurs.
-
toJar
public java.io.File toJar(java.io.File file) throws java.io.IOExceptionSaves the contents of this dynamic type inside a jar file. The folder of the givenfilemust exist prior to calling this method. The jar file is created with a simple manifest that only contains a version number. No directory entries are added to the generated jar.- Specified by:
toJarin interfaceDynamicType- Parameters:
file- The target file to which the jar is written to.- Returns:
- The given
file. - Throws:
java.io.IOException- If an I/O exception occurs while writing the file.
-
toJar
public java.io.File toJar(java.io.File file, java.util.jar.Manifest manifest) throws java.io.IOExceptionSaves the contents of this dynamic type inside a jar file. The folder of the givenfilemust exist prior to calling this method. No directory entries are added to the generated jar.- Specified by:
toJarin interfaceDynamicType- Parameters:
file- The target file to which the jar is written to.manifest- The manifest of the created jar.- Returns:
- The given
file. - Throws:
java.io.IOException- If an I/O exception occurs while writing the file.
-
-