Class DynamicType.Default
- java.lang.Object
-
- net.bytebuddy.dynamic.DynamicType.Default
-
- All Implemented Interfaces:
DynamicType
- Direct Known Subclasses:
DynamicType.Default.Loaded
,DynamicType.Default.Unloaded
- Enclosing interface:
- DynamicType
public static class DynamicType.Default extends java.lang.Object implements DynamicType
A default implementation of a dynamic type.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
DynamicType.Default.Loaded<T>
A default implementation of a loaded dynamic type.static class
DynamicType.Default.Unloaded<T>
A default implementation of an unloaded dynamic type.-
Nested classes/interfaces inherited from interface net.bytebuddy.dynamic.DynamicType
DynamicType.Builder<T>, DynamicType.Default
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.List<? extends DynamicType>
auxiliaryTypes
A list of auxiliary types for this dynamic type.protected byte[]
binaryRepresentation
The byte array representing this dynamic type.protected LoadedTypeInitializer
loadedTypeInitializer
The loaded type initializer for this dynamic type.protected TypeDescription
typeDescription
A type description of this dynamic type.
-
Constructor Summary
Constructors Constructor Description Default(TypeDescription typeDescription, byte[] binaryRepresentation, LoadedTypeInitializer loadedTypeInitializer, java.util.List<? extends DynamicType> auxiliaryTypes)
Creates a new dynamic type.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.Object other)
java.util.Map<TypeDescription,byte[]>
getAllTypes()
Returns all types that are implied 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.byte[]
getBytes()
Returns a byte array representing this dynamic 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.TypeDescription
getTypeDescription()
Returns a description of this dynamic type.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.int
hashCode()
java.io.File
inject(java.io.File jar)
Injects the types of this dynamic type into a given jar file.java.io.File
inject(java.io.File sourceJar, java.io.File targetJar)
Injects the types of this dynamic type into a given jar 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.File
toJar(java.io.File file)
Saves the contents of this dynamic type inside a jar file.java.io.File
toJar(java.io.File file, java.util.jar.Manifest manifest)
Saves the contents of this dynamic type inside a jar file.
-
-
-
Field Detail
-
typeDescription
protected final TypeDescription typeDescription
A type description of this dynamic type.
-
binaryRepresentation
protected final byte[] binaryRepresentation
The byte array representing this dynamic type.
-
loadedTypeInitializer
protected final LoadedTypeInitializer loadedTypeInitializer
The loaded type initializer for this dynamic type.
-
auxiliaryTypes
protected final java.util.List<? extends DynamicType> auxiliaryTypes
A list of auxiliary types for this dynamic type.
-
-
Constructor Detail
-
Default
public Default(TypeDescription typeDescription, byte[] binaryRepresentation, LoadedTypeInitializer loadedTypeInitializer, java.util.List<? extends DynamicType> auxiliaryTypes)
Creates a new dynamic type.- Parameters:
typeDescription
- A description of this dynamic type.binaryRepresentation
- A byte array containing the binary representation of this dynamic type. The array must not be modified.loadedTypeInitializer
- The loaded type initializer of this dynamic type.auxiliaryTypes
- The auxiliary type required for this dynamic type.
-
-
Method Detail
-
getTypeDescription
public TypeDescription getTypeDescription()
Description copied from interface:DynamicType
Returns a description of this dynamic type.
Note: This description will most likely differ from the binary representation of this type. Normally, annotations and intercepted methods are not added to this type description.
- Specified by:
getTypeDescription
in interfaceDynamicType
- Returns:
- A description of this dynamic type.
-
getAllTypes
public java.util.Map<TypeDescription,byte[]> getAllTypes()
Description copied from interface:DynamicType
Returns all types that are implied by this dynamic type.- Specified by:
getAllTypes
in 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()
Description copied from interface:DynamicType
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:
getLoadedTypeInitializers
in interfaceDynamicType
- Returns:
- A mapping of all types' descriptions to their loaded type initializers.
-
hasAliveLoadedTypeInitializers
public boolean hasAliveLoadedTypeInitializers()
Description copied from interface:DynamicType
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:
hasAliveLoadedTypeInitializers
in interfaceDynamicType
- Returns:
true
if this type requires explicit type initialization.
-
getBytes
public byte[] getBytes()
Description copied from interface:DynamicType
Returns a byte array representing this dynamic type. This byte array might be reused by this dynamic type and must therefore not be altered.- Specified by:
getBytes
in interfaceDynamicType
- Returns:
- A byte array of the type's binary representation.
-
getAuxiliaryTypes
public java.util.Map<TypeDescription,byte[]> getAuxiliaryTypes()
Description copied from interface:DynamicType
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:
getAuxiliaryTypes
in 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
Description copied from interface:DynamicType
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
folder
does 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:
saveIn
in 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.IOException
Description copied from interface:DynamicType
Injects the types of this dynamic type into a given jar file. Any pre-existent type with the same name is overridden during injection. Thetarget
file's folder must exist prior to calling this method. The file itself is overwritten or created depending on its prior existence.- Specified by:
inject
in interfaceDynamicType
- Parameters:
sourceJar
- The original jar file.targetJar
- Thesource
jar file with the injected contents.- Returns:
- The
target
jar 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.IOException
Description copied from interface:DynamicType
Injects the types of this dynamic type into a given jar file. Any pre-existent type with the same name is overridden during injection.- Specified by:
inject
in interfaceDynamicType
- Parameters:
jar
- The jar file to replace with an injected version.- Returns:
- The
jar
file. - Throws:
java.io.IOException
- If an I/O exception occurs while injecting into the jar.
-
toJar
public java.io.File toJar(java.io.File file) throws java.io.IOException
Description copied from interface:DynamicType
Saves the contents of this dynamic type inside a jar file. The folder of the givenfile
must exist prior to calling this method. The jar file is created with a simple manifest that only contains a version number.- Specified by:
toJar
in 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.IOException
Description copied from interface:DynamicType
Saves the contents of this dynamic type inside a jar file. The folder of the givenfile
must exist prior to calling this method.- Specified by:
toJar
in 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.
-
equals
public boolean equals(java.lang.Object other)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
-