Class ClassDefinitionUtils
java.lang.Object
org.objenesis.instantiator.exotic.util.ClassDefinitionUtils
Helper class for ProxyObjectInstantiator. We can see the details of a class specification
here
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final byte[]
static final byte
static final byte
static final byte
static final byte
static final byte
static final byte
private static final ProtectionDomain
static final byte[]
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Class
<T> defineClass
(String className, byte[] b, Class<?> neighbor, ClassLoader loader) Define a class in the provided class loader from the array of bytes.static byte[]
Read the bytes of a class from the classpathstatic void
writeClass
(String fileName, byte[] bytes) Write all class bytes to a file.
-
Field Details
-
OPS_aload_0
public static final byte OPS_aload_0- See Also:
-
OPS_invokespecial
public static final byte OPS_invokespecial- See Also:
-
OPS_return
public static final byte OPS_return- See Also:
-
OPS_new
public static final byte OPS_new- See Also:
-
OPS_dup
public static final byte OPS_dup- See Also:
-
OPS_areturn
public static final byte OPS_areturn- See Also:
-
CONSTANT_Utf8
public static final int CONSTANT_Utf8- See Also:
-
CONSTANT_Integer
public static final int CONSTANT_Integer- See Also:
-
CONSTANT_Float
public static final int CONSTANT_Float- See Also:
-
CONSTANT_Long
public static final int CONSTANT_Long- See Also:
-
CONSTANT_Double
public static final int CONSTANT_Double- See Also:
-
CONSTANT_Class
public static final int CONSTANT_Class- See Also:
-
CONSTANT_String
public static final int CONSTANT_String- See Also:
-
CONSTANT_Fieldref
public static final int CONSTANT_Fieldref- See Also:
-
CONSTANT_Methodref
public static final int CONSTANT_Methodref- See Also:
-
CONSTANT_InterfaceMethodref
public static final int CONSTANT_InterfaceMethodref- See Also:
-
CONSTANT_NameAndType
public static final int CONSTANT_NameAndType- See Also:
-
CONSTANT_MethodHandle
public static final int CONSTANT_MethodHandle- See Also:
-
CONSTANT_MethodType
public static final int CONSTANT_MethodType- See Also:
-
CONSTANT_InvokeDynamic
public static final int CONSTANT_InvokeDynamic- See Also:
-
ACC_PUBLIC
public static final int ACC_PUBLIC- See Also:
-
ACC_FINAL
public static final int ACC_FINAL- See Also:
-
ACC_SUPER
public static final int ACC_SUPER- See Also:
-
ACC_INTERFACE
public static final int ACC_INTERFACE- See Also:
-
ACC_ABSTRACT
public static final int ACC_ABSTRACT- See Also:
-
ACC_SYNTHETIC
public static final int ACC_SYNTHETIC- See Also:
-
ACC_ANNOTATION
public static final int ACC_ANNOTATION- See Also:
-
ACC_ENUM
public static final int ACC_ENUM- See Also:
-
MAGIC
public static final byte[] MAGIC -
VERSION
public static final byte[] VERSION -
PROTECTION_DOMAIN
-
-
Constructor Details
-
ClassDefinitionUtils
private ClassDefinitionUtils()
-
-
Method Details
-
defineClass
public static <T> Class<T> defineClass(String className, byte[] b, Class<?> neighbor, ClassLoader loader) throws Exception Define a class in the provided class loader from the array of bytes. Inspired by cglibReflectUtils.defineClass
- Type Parameters:
T
- type of the class returned- Parameters:
className
- class name in the formatorg.objenesis.MyClass
b
- bytes representing the classneighbor
- a class in the same package as the loaded classloader
- the class loader where the class will be loaded- Returns:
- the newly loaded class
- Throws:
Exception
- whenever something goes wrong
-
readClass
Read the bytes of a class from the classpath- Parameters:
className
- full class name including the package- Returns:
- the bytes representing the class
- Throws:
IllegalArgumentException
- if the class is longer than 2500 bytesIOException
- if we fail to read the class
-
writeClass
Write all class bytes to a file.- Parameters:
fileName
- file where the bytes will be writtenbytes
- bytes representing the class- Throws:
IOException
- if we fail to write the class
-