public final class ClassDefinitionUtils
extends java.lang.Object
限定符和类型 | 字段和说明 |
---|---|
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 |
static byte[] |
VERSION |
限定符和类型 | 方法和说明 |
---|---|
static java.lang.String |
classNameToInternalClassName(java.lang.String className)
Will convert a class name to its name in the class definition format (e.g
org.objenesis.EmptyClass
becomes org/objenesis/EmptyClass ) |
static java.lang.String |
classNameToResource(java.lang.String className)
Will convert a class name to its class loader resource name (e.g
org.objenesis.EmptyClass
becomes org/objenesis/EmptyClass.class ) |
static <T> java.lang.Class<T> |
defineClass(java.lang.String className,
byte[] b,
java.lang.ClassLoader loader)
Define a class in the provided class loader from the array of bytes.
|
static <T> java.lang.Class<T> |
getExistingClass(java.lang.ClassLoader classLoader,
java.lang.String className)
Check if this class already exists in the class loader and return it if it does
|
static byte[] |
readClass(java.lang.String className)
Read the bytes of a class from the classpath
|
static void |
writeClass(java.lang.String fileName,
byte[] bytes)
Write all class bytes to a file.
|
public static final byte OPS_aload_0
public static final byte OPS_invokespecial
public static final byte OPS_return
public static final byte OPS_new
public static final byte OPS_dup
public static final byte OPS_areturn
public static final int CONSTANT_Utf8
public static final int CONSTANT_Integer
public static final int CONSTANT_Float
public static final int CONSTANT_Long
public static final int CONSTANT_Double
public static final int CONSTANT_Class
public static final int CONSTANT_String
public static final int CONSTANT_Fieldref
public static final int CONSTANT_Methodref
public static final int CONSTANT_InterfaceMethodref
public static final int CONSTANT_NameAndType
public static final int CONSTANT_MethodHandle
public static final int CONSTANT_MethodType
public static final int CONSTANT_InvokeDynamic
public static final int ACC_PUBLIC
public static final int ACC_FINAL
public static final int ACC_SUPER
public static final int ACC_INTERFACE
public static final int ACC_ABSTRACT
public static final int ACC_SYNTHETIC
public static final int ACC_ANNOTATION
public static final int ACC_ENUM
public static final byte[] MAGIC
public static final byte[] VERSION
public static <T> java.lang.Class<T> defineClass(java.lang.String className, byte[] b, java.lang.ClassLoader loader) throws java.lang.Exception
ReflectUtils.defineClass
T
- type of the class returnedclassName
- class name in the format org.objenesis.MyClass
b
- bytes representing the classloader
- the class loader where the class will be loadedjava.lang.Exception
- whenever something goes wrongpublic static byte[] readClass(java.lang.String className) throws java.io.IOException
className
- full class name including the packagejava.lang.IllegalArgumentException
- if the class is longer than 2500 bytesjava.io.IOException
- if we fail to read the classpublic static void writeClass(java.lang.String fileName, byte[] bytes) throws java.io.IOException
fileName
- file where the bytes will be writtenbytes
- bytes representing the classjava.io.IOException
- if we fail to write the classpublic static java.lang.String classNameToInternalClassName(java.lang.String className)
org.objenesis.EmptyClass
becomes org/objenesis/EmptyClass
)className
- full class name including the packagepublic static java.lang.String classNameToResource(java.lang.String className)
org.objenesis.EmptyClass
becomes org/objenesis/EmptyClass.class
)className
- full class name including the packagepublic static <T> java.lang.Class<T> getExistingClass(java.lang.ClassLoader classLoader, java.lang.String className)
T
- type of the class returnedclassLoader
- Class loader where to search the classclassName
- Class name with full path