Package org.objenesis.instantiator.util
Class ClassDefinitionUtils
- java.lang.Object
-
- org.objenesis.instantiator.util.ClassDefinitionUtils
-
public final class ClassDefinitionUtils extends java.lang.Object
Helper class for ProxyObjectInstantiator. We can see the details of a class specification here
-
-
Field Summary
Fields Modifier and Type Field Description static int
ACC_ABSTRACT
static int
ACC_ANNOTATION
static int
ACC_ENUM
static int
ACC_FINAL
static int
ACC_INTERFACE
static int
ACC_PUBLIC
static int
ACC_SUPER
static int
ACC_SYNTHETIC
static int
CONSTANT_Class
static int
CONSTANT_Double
static int
CONSTANT_Fieldref
static int
CONSTANT_Float
static int
CONSTANT_Integer
static int
CONSTANT_InterfaceMethodref
static int
CONSTANT_InvokeDynamic
static int
CONSTANT_Long
static int
CONSTANT_MethodHandle
static int
CONSTANT_Methodref
static int
CONSTANT_MethodType
static int
CONSTANT_NameAndType
static int
CONSTANT_String
static int
CONSTANT_Utf8
static byte[]
MAGIC
static byte
OPS_aload_0
static byte
OPS_areturn
static byte
OPS_dup
static byte
OPS_invokespecial
static byte
OPS_new
static byte
OPS_return
private static java.security.ProtectionDomain
PROTECTION_DOMAIN
static byte[]
VERSION
-
Constructor Summary
Constructors Modifier Constructor Description private
ClassDefinitionUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> java.lang.Class<T>
defineClass(java.lang.String className, byte[] b, java.lang.Class<?> neighbor, java.lang.ClassLoader loader)
Define a class in the provided class loader from the array of bytes.static byte[]
readClass(java.lang.String className)
Read the bytes of a class from the classpathstatic void
writeClass(java.lang.String fileName, byte[] bytes)
Write all class bytes to a file.
-
-
-
Field Detail
-
OPS_aload_0
public static final byte OPS_aload_0
- See Also:
- Constant Field Values
-
OPS_invokespecial
public static final byte OPS_invokespecial
- See Also:
- Constant Field Values
-
OPS_return
public static final byte OPS_return
- See Also:
- Constant Field Values
-
OPS_new
public static final byte OPS_new
- See Also:
- Constant Field Values
-
OPS_dup
public static final byte OPS_dup
- See Also:
- Constant Field Values
-
OPS_areturn
public static final byte OPS_areturn
- See Also:
- Constant Field Values
-
CONSTANT_Utf8
public static final int CONSTANT_Utf8
- See Also:
- Constant Field Values
-
CONSTANT_Integer
public static final int CONSTANT_Integer
- See Also:
- Constant Field Values
-
CONSTANT_Float
public static final int CONSTANT_Float
- See Also:
- Constant Field Values
-
CONSTANT_Long
public static final int CONSTANT_Long
- See Also:
- Constant Field Values
-
CONSTANT_Double
public static final int CONSTANT_Double
- See Also:
- Constant Field Values
-
CONSTANT_Class
public static final int CONSTANT_Class
- See Also:
- Constant Field Values
-
CONSTANT_String
public static final int CONSTANT_String
- See Also:
- Constant Field Values
-
CONSTANT_Fieldref
public static final int CONSTANT_Fieldref
- See Also:
- Constant Field Values
-
CONSTANT_Methodref
public static final int CONSTANT_Methodref
- See Also:
- Constant Field Values
-
CONSTANT_InterfaceMethodref
public static final int CONSTANT_InterfaceMethodref
- See Also:
- Constant Field Values
-
CONSTANT_NameAndType
public static final int CONSTANT_NameAndType
- See Also:
- Constant Field Values
-
CONSTANT_MethodHandle
public static final int CONSTANT_MethodHandle
- See Also:
- Constant Field Values
-
CONSTANT_MethodType
public static final int CONSTANT_MethodType
- See Also:
- Constant Field Values
-
CONSTANT_InvokeDynamic
public static final int CONSTANT_InvokeDynamic
- See Also:
- Constant Field Values
-
ACC_PUBLIC
public static final int ACC_PUBLIC
- See Also:
- Constant Field Values
-
ACC_FINAL
public static final int ACC_FINAL
- See Also:
- Constant Field Values
-
ACC_SUPER
public static final int ACC_SUPER
- See Also:
- Constant Field Values
-
ACC_INTERFACE
public static final int ACC_INTERFACE
- See Also:
- Constant Field Values
-
ACC_ABSTRACT
public static final int ACC_ABSTRACT
- See Also:
- Constant Field Values
-
ACC_SYNTHETIC
public static final int ACC_SYNTHETIC
- See Also:
- Constant Field Values
-
ACC_ANNOTATION
public static final int ACC_ANNOTATION
- See Also:
- Constant Field Values
-
ACC_ENUM
public static final int ACC_ENUM
- See Also:
- Constant Field Values
-
MAGIC
public static final byte[] MAGIC
-
VERSION
public static final byte[] VERSION
-
PROTECTION_DOMAIN
private static final java.security.ProtectionDomain PROTECTION_DOMAIN
-
-
Method Detail
-
defineClass
public static <T> java.lang.Class<T> defineClass(java.lang.String className, byte[] b, java.lang.Class<?> neighbor, java.lang.ClassLoader loader) throws java.lang.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:
java.lang.Exception
- whenever something goes wrong
-
readClass
public static byte[] readClass(java.lang.String className) throws java.io.IOException
Read the bytes of a class from the classpath- Parameters:
className
- full class name including the package- Returns:
- the bytes representing the class
- Throws:
java.lang.IllegalArgumentException
- if the class is longer than 2500 bytesjava.io.IOException
- if we fail to read the class
-
writeClass
public static void writeClass(java.lang.String fileName, byte[] bytes) throws java.io.IOException
Write all class bytes to a file.- Parameters:
fileName
- file where the bytes will be writtenbytes
- bytes representing the class- Throws:
java.io.IOException
- if we fail to write the class
-
-