Package org.objenesis.instantiator.util
Class ClassDefinitionUtils
- java.lang.Object
-
- org.objenesis.instantiator.util.ClassDefinitionUtils
-
public final class ClassDefinitionUtils extends java.lang.ObjectHelper class for ProxyObjectInstantiator. We can see the details of a class specification here
-
-
Field Summary
Fields Modifier and Type Field Description static intACC_ABSTRACTstatic intACC_ANNOTATIONstatic intACC_ENUMstatic intACC_FINALstatic intACC_INTERFACEstatic intACC_PUBLICstatic intACC_SUPERstatic intACC_SYNTHETICstatic intCONSTANT_Classstatic intCONSTANT_Doublestatic intCONSTANT_Fieldrefstatic intCONSTANT_Floatstatic intCONSTANT_Integerstatic intCONSTANT_InterfaceMethodrefstatic intCONSTANT_InvokeDynamicstatic intCONSTANT_Longstatic intCONSTANT_MethodHandlestatic intCONSTANT_Methodrefstatic intCONSTANT_MethodTypestatic intCONSTANT_NameAndTypestatic intCONSTANT_Stringstatic intCONSTANT_Utf8static byte[]MAGICstatic byteOPS_aload_0static byteOPS_areturnstatic byteOPS_dupstatic byteOPS_invokespecialstatic byteOPS_newstatic byteOPS_returnprivate static java.security.ProtectionDomainPROTECTION_DOMAINstatic byte[]VERSION
-
Constructor Summary
Constructors Modifier Constructor Description privateClassDefinitionUtils()
-
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 voidwriteClass(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.ExceptionDefine 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.MyClassb- 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.IOExceptionRead 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.IOExceptionWrite 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
-
-