Class ClassFile
- All Implemented Interfaces:
Annotatable
ClassFile(InputStream)
reads bytecode from an InputStream
and creates a ClassFile
object
from it.
store(OutputStream)
generates JVM bytecode which is suitable for being processed by a Java
virtual machine, and writes it to an OutputStream
.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
The structure of theannotations
array as described in JVMS8 4.7.16.static class
Representation of anAnnotationDefault
attribute (see JVMS8 4.7.22).static class
Representation of aRuntime[In]visibleAnnotations
attribute (see JVMS8 4.7.16/17).static final class
Representation of the "array_value" structure.static class
Representation of a class file attribute (see JVMS7 4.7).static final class
static final class
static final class
static final class
static class
Unchecked exception that represents an error condition that could occur during processing of class files, e.g.static class
Representation of an unmodifiableCode
attribute, as read from a class file.static class
See JVMS7 4.4.1.private static class
See JVMS7 4.4.5.static class
Convenience class for element values that are constants (as opposed to annotations, enum constants and arrays).static class
See JVMS7 4.4.2.private static class
See JVMS7 4.4.4.private static class
See JVMS7 4.4.4.static class
See JVMS7 4.4.2.static class
See JVMS7 4.4.10.private static class
See JVMS7 4.4.5.static class
See JVMS7 4.4.8.static class
See JVMS7 4.4.2.static class
See JVMS7 4.4.9.static class
See JVMS7 4.4.6.static class
Base for various the constant pool table entry types.(package private) static class
See JVMS7 4.4.3.static class
See JVMS7 4.4.7.static class
Representation of aConstantValue
attribute (see JVMS 4.7.2).static class
Intermediate base class for constant pool table entry types that have 'value' semantics: Double, Float, Integer, Long, Stringstatic class
Representation of aDeprecated
attribute (see JVMS 4.7.10).static final class
static interface
Representation of the "element_value" structure (see JVMS8 4.7.16.1).static final class
Representation of the "enum_const_value" element in the "element_value" structure.static class
Representation of anExceptions
attribute (see JVMS 4.7.4).class
Representation of a "method_info" structure, as defined by JVMS7 4.5.static final class
static class
Representation of anInnerClasses
attribute (see JVMS 4.7.5).static final class
static class
Representation of aLineNumberTable
attribute (see JVMS 4.7.8).static class
Representation of aLocalVariableTable
attribute (see JVMS 4.7.9).static final class
class
Representation of a "method_info" structure, as defined by JVMS7 4.6.static final class
static class
Representation of aSignature
attribute (see JVMS 4.7.9).static class
Representation of aSourceFile
attribute (see JVMS 4.7.7).static class
Representation of an unmodifiableStackMapTable
attribute, as read from a class file.static final class
static class
Representation of aSynthetic
attribute (see JVMS 4.7.6). -
Field Summary
FieldsModifier and TypeFieldDescriptionfinal short
The access flags of the class.private final List
<ClassFile.AttributeInfo> TheClassFile.AttributeInfo
s of the attributes of this class or interface.private static final int
private final List
<ClassFile.ConstantPoolInfo> private final Map
<ClassFile.ConstantPoolInfo, Short> final List
<ClassFile.FieldInfo> TheClassFile.FieldInfo
s of the field members of this class or interface.final short[]
The constant pool indexes ofClassFile.ConstantClassInfo
which describe the interfaces that this class implements, resp.static final short
Major version number of a class file that was generated by a Java 1.1-compliant compiler.static final short
Major version number of a class file that was generated by a Java 1.10-compliant compiler.static final short
Major version number of a class file that was generated by a Java 1.11-compliant compiler.static final short
Major version number of a class file that was generated by a Java 1.12-compliant compiler.static final short
Major version number of a class file that was generated by a Java 1.2-compliant compiler.static final short
Major version number of a class file that was generated by a Java 1.3-compliant compiler.static final short
Major version number of a class file that was generated by a Java 1.4-compliant compiler.static final short
Major version number of a class file that was generated by a Java 1.5-compliant compiler.static final short
Major version number of a class file that was generated by a Java 1.6-compliant compiler.static final short
Major version number of a class file that was generated by a Java 1.7-compliant compiler.static final short
Major version number of a class file that was generated by a Java 1.8-compliant compiler.static final short
Major version number of a class file that was generated by a Java 1.9-compliant compiler.private short
final List
<ClassFile.MethodInfo> TheClassFile.MethodInfo
s of the methods of this class or interface.static final short
Minor version number of a class file that was generated by a Java 1.1-compliant compiler.static final short
Minor version number of a class file that was generated by a Java 1.10-compliant compiler.static final short
Minor version number of a class file that was generated by a Java 1.11-compliant compiler.static final short
Minor version number of a class file that was generated by a Java 1.12-compliant compiler.static final short
Minor version number of a class file that was generated by a Java 1.2-compliant compiler.static final short
Minor version number of a class file that was generated by a Java 1.3-compliant compiler.static final short
Minor version number of a class file that was generated by a Java 1.4-compliant compiler.static final short
Minor version number of a class file that was generated by a Java 1.5-compliant compiler.static final short
Minor version number of a class file that was generated by a Java 1.6-compliant compiler.static final short
Minor version number of a class file that was generated by a Java 1.7-compliant compiler.static final short
Minor version number of a class file that was generated by a Java 1.8-compliant compiler.static final short
Minor version number of a class file that was generated by a Java 1.9-compliant compiler.private short
final short
The constant pool index of theClassFile.ConstantClassInfo
that describes the superclass of this class.final short
The constant pool index of theClassFile.ConstantClassInfo
that describes this class. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addAnnotationsAttributeEntry
(boolean runtimeVisible, String fieldDescriptor, Map<Short, ClassFile.ElementValue> elementValuePairs) Creates aRuntime[In]visibleAnnotations
attribute on the class (if it does not yet exist) and adds an entry to it.private void
addAnnotationsAttributeEntry
(boolean runtimeVisible, String fieldDescriptor, Map<Short, ClassFile.ElementValue> elementValuePairs, List<ClassFile.AttributeInfo> target) Adds aRuntime[In]visibleAnnotations
attribute to the target (if it does not yet exist) and adds an entry to it.short
addConstantClassInfo
(String typeFd) Returns the constant index number for a "CONSTANT_Class_info" structure to the class file.short
addConstantDoubleInfo
(double value) Adds a "CONSTANT_Double_info" structure to the class file.short
addConstantFieldrefInfo
(String classFd, String fieldName, String fieldFd) Adds a "CONSTANT_Fieldref_info" structure to the class file.short
addConstantFloatInfo
(float value) Adds a "CONSTANT_Float_info" structure to the class file.short
addConstantIntegerInfo
(int value) Adds a "CONSTANT_Integer_info" structure to the class file.short
addConstantInterfaceMethodrefInfo
(String classFd, String methodName, String methodMd) Adds a "CONSTANT_InterfaceMethodref_info" structure to the class file.short
addConstantLongInfo
(long value) Adds a "CONSTANT_Long_info" structure to the class file.short
addConstantMethodrefInfo
(String classFd, String methodName, String methodMd) Adds a "CONSTANT_Methodref_info" structure to the class file.private short
addConstantNameAndTypeInfo
(String name, String descriptor) Adds a "CONSTANT_NameAndType_info" structure to the class file.private short
Convenience method that adds a String, Integer, Float, Long or Double ConstantInfo.short
addConstantStringInfo
(String string) Adds a "CONSTANT_String_info" structure to the class file.short
Adds a "CONSTANT_Utf8_info" structure to the class file if no equal entry exists.void
Adds theDeprecated
attribute to this class.addFieldInfo
(short accessFlags, String fieldName, String fieldTypeFd, Object constantValue) Creates aClassFile.FieldInfo
and adds it to this class.void
Creates anInnerClasses
attribute if it does not exist, then adds the entry to theInnerClasses
attribute.addMethodInfo
(short accessFlags, String methodName, MethodDescriptor methodMd) Creates aClassFile.MethodInfo
and adds it to this class.void
addSourceFileAttribute
(String sourceFileName) Adds aSourceFile
attribute to this class file.private short
Adds an entry to the constant pool and returns its index, or, if an equal entry already exists in the constant pool, returns the index of that entry.private ClassFile.AttributeInfo
findAttribute
(List<ClassFile.AttributeInfo> attributes, String attributeName) Finds the named attribute in the attributes.getAnnotations
(boolean runtimeVisible) private ClassFile.AnnotationsAttribute
getAnnotationsAttribute
(boolean runtimeVisible, List<ClassFile.AttributeInfo> attributes) Finds theRuntime[In]visibleAnnotations
attribute in the attributes.static String
getClassFileResourceName
(String className) Constructs the name of a resource that could contain the class file of the class with the className.getConstantClassInfo
(short index) getConstantFieldrefInfo
(short index) getConstantInterfaceMethodrefInfo
(short index) getConstantInvokeDynamicInfo
(short index) getConstantMethodHandleInfo
(short index) getConstantMethodrefInfo
(short index) getConstantMethodTypeInfo
(short index) getConstantNameAndTypeInfo
(short index) getConstantPoolInfo
(short index) int
getConstantUtf8
(short index) Shorthand forgetConstantUtf8Info(index).s
.getConstantUtf8Info
(short index) getConstantValuePoolInfo
(short index) Finds theInnerClasses
attribute of this class file.short
short
static String
getSourceResourceName
(String className) Constructs the name of a resource that could contain the source code of the class with the className.private ClassFile.AttributeInfo
Loads one class file attribute.private List
<ClassFile.AttributeInfo> u2 attributes_count, attributes[attributes_count]private void
u2 constant_pool_count, constant_pool[constant_pool_count]private static ClassFile.ElementValue
private List
<ClassFile.FieldInfo> u2 fields_count, fields[fields_count]private ClassFile.MethodInfo
private List
<ClassFile.MethodInfo> u2 methods_count, methods[methods_count]newObjectVariableInfo
(String fieldDescriptor) newUninitializedVariableInfo
(short offset) private static byte[]
u4 length, u1[length]private static short[]
u2 length, u2[length]void
setVersion
(short majorVersion, short minorVersion) Sets the major and minor class file version numbers (JVMS 4.1).void
store
(OutputStream os) WritesClassFile
to anOutputStream
, in "class file" format.private static void
storeAttributes
(DataOutputStream dos, List<ClassFile.AttributeInfo> attributeInfos) u2 attributes_count, attributes[attributes_count]private static void
storeConstantPool
(DataOutputStream dos, List<ClassFile.ConstantPoolInfo> constantPool) u2 constant_pool_count, constant_pool[constant_pool_count - 1]private static void
storeFields
(DataOutputStream dos, List<ClassFile.FieldInfo> fieldInfos) u2 fields_count, fields[fields_count]private static void
storeMethods
(DataOutputStream dos, List<ClassFile.MethodInfo> methodInfos) u2 methods_count, methods[methods_count]private static void
storeShortArray
(DataOutputStream dos, short[] sa) u2 count, u2[count]byte[]
Returns the byte code of thisClassFile
as a byte array.toString()
-
Field Details
-
CLASS_FILE_MAGIC
private static final int CLASS_FILE_MAGIC- See Also:
-
MAJOR_VERSION_JDK_1_1
public static final short MAJOR_VERSION_JDK_1_1Major version number of a class file that was generated by a Java 1.1-compliant compiler.- See Also:
-
MINOR_VERSION_JDK_1_1
public static final short MINOR_VERSION_JDK_1_1Minor version number of a class file that was generated by a Java 1.1-compliant compiler.- See Also:
-
MAJOR_VERSION_JDK_1_2
public static final short MAJOR_VERSION_JDK_1_2Major version number of a class file that was generated by a Java 1.2-compliant compiler.- See Also:
-
MINOR_VERSION_JDK_1_2
public static final short MINOR_VERSION_JDK_1_2Minor version number of a class file that was generated by a Java 1.2-compliant compiler.- See Also:
-
MAJOR_VERSION_JDK_1_3
public static final short MAJOR_VERSION_JDK_1_3Major version number of a class file that was generated by a Java 1.3-compliant compiler.- See Also:
-
MINOR_VERSION_JDK_1_3
public static final short MINOR_VERSION_JDK_1_3Minor version number of a class file that was generated by a Java 1.3-compliant compiler.- See Also:
-
MAJOR_VERSION_JDK_1_4
public static final short MAJOR_VERSION_JDK_1_4Major version number of a class file that was generated by a Java 1.4-compliant compiler.- See Also:
-
MINOR_VERSION_JDK_1_4
public static final short MINOR_VERSION_JDK_1_4Minor version number of a class file that was generated by a Java 1.4-compliant compiler.- See Also:
-
MAJOR_VERSION_JDK_1_5
public static final short MAJOR_VERSION_JDK_1_5Major version number of a class file that was generated by a Java 1.5-compliant compiler.- See Also:
-
MINOR_VERSION_JDK_1_5
public static final short MINOR_VERSION_JDK_1_5Minor version number of a class file that was generated by a Java 1.5-compliant compiler.- See Also:
-
MAJOR_VERSION_JDK_1_6
public static final short MAJOR_VERSION_JDK_1_6Major version number of a class file that was generated by a Java 1.6-compliant compiler.- See Also:
-
MINOR_VERSION_JDK_1_6
public static final short MINOR_VERSION_JDK_1_6Minor version number of a class file that was generated by a Java 1.6-compliant compiler.- See Also:
-
MAJOR_VERSION_JDK_1_7
public static final short MAJOR_VERSION_JDK_1_7Major version number of a class file that was generated by a Java 1.7-compliant compiler.- See Also:
-
MINOR_VERSION_JDK_1_7
public static final short MINOR_VERSION_JDK_1_7Minor version number of a class file that was generated by a Java 1.7-compliant compiler.- See Also:
-
MAJOR_VERSION_JDK_1_8
public static final short MAJOR_VERSION_JDK_1_8Major version number of a class file that was generated by a Java 1.8-compliant compiler.- See Also:
-
MINOR_VERSION_JDK_1_8
public static final short MINOR_VERSION_JDK_1_8Minor version number of a class file that was generated by a Java 1.8-compliant compiler.- See Also:
-
MAJOR_VERSION_JDK_1_9
public static final short MAJOR_VERSION_JDK_1_9Major version number of a class file that was generated by a Java 1.9-compliant compiler.- See Also:
-
MINOR_VERSION_JDK_1_9
public static final short MINOR_VERSION_JDK_1_9Minor version number of a class file that was generated by a Java 1.9-compliant compiler.- See Also:
-
MAJOR_VERSION_JDK_1_10
public static final short MAJOR_VERSION_JDK_1_10Major version number of a class file that was generated by a Java 1.10-compliant compiler.- See Also:
-
MINOR_VERSION_JDK_1_10
public static final short MINOR_VERSION_JDK_1_10Minor version number of a class file that was generated by a Java 1.10-compliant compiler.- See Also:
-
MAJOR_VERSION_JDK_1_11
public static final short MAJOR_VERSION_JDK_1_11Major version number of a class file that was generated by a Java 1.11-compliant compiler.- See Also:
-
MINOR_VERSION_JDK_1_11
public static final short MINOR_VERSION_JDK_1_11Minor version number of a class file that was generated by a Java 1.11-compliant compiler.- See Also:
-
MAJOR_VERSION_JDK_1_12
public static final short MAJOR_VERSION_JDK_1_12Major version number of a class file that was generated by a Java 1.12-compliant compiler.- See Also:
-
MINOR_VERSION_JDK_1_12
public static final short MINOR_VERSION_JDK_1_12Minor version number of a class file that was generated by a Java 1.12-compliant compiler.- See Also:
-
majorVersion
private short majorVersion -
minorVersion
private short minorVersion -
constantPool
-
accessFlags
public final short accessFlagsThe access flags of the class.- See Also:
-
thisClass
public final short thisClassThe constant pool index of theClassFile.ConstantClassInfo
that describes this class. -
superclass
public final short superclassThe constant pool index of theClassFile.ConstantClassInfo
that describes the superclass of this class. Zero for classObject
,Object
for interfaces.- See Also:
-
interfaces
public final short[] interfacesThe constant pool indexes ofClassFile.ConstantClassInfo
which describe the interfaces that this class implements, resp. that this interface extends. -
fieldInfos
TheClassFile.FieldInfo
s of the field members of this class or interface. -
methodInfos
TheClassFile.MethodInfo
s of the methods of this class or interface. -
attributes
TheClassFile.AttributeInfo
s of the attributes of this class or interface. -
constantPoolMap
-
-
Constructor Details
-
ClassFile
public ClassFile(short accessFlags, String thisClassFd, @Nullable String superclassFd, String[] interfaceFds) Constructs a class with no fields and methods. An application would typically add fields and methods before saving it.By default, the .class file major and minor version are that of the currently executing JVM (system property
"java.class.version"
). -
ClassFile
Reads "class file" data from the inputStream and construct aClassFile
object from it.If the
ClassFile
is created with this constructor, then most modifying operations lead to aUnsupportedOperationException
; only fields, methods and attributes can be added.- Throws:
IOException
-
-
Method Details
-
addSourceFileAttribute
Adds aSourceFile
attribute to this class file. (Does not check whether one exists already.)- Parameters:
sourceFileName
-
-
addDeprecatedAttribute
public void addDeprecatedAttribute()Adds theDeprecated
attribute to this class. -
getInnerClassesAttribute
Finds theInnerClasses
attribute of this class file.- Returns:
null
if this class has no "InnerClasses" attribute
-
getSignatureAttribute
-
findAttribute
@Nullable private ClassFile.AttributeInfo findAttribute(List<ClassFile.AttributeInfo> attributes, String attributeName) throws ClassFormatError Finds the named attribute in the attributes.- Returns:
null
iff the attributes constain no attribute with that name- Throws:
ClassFile.ClassFileException
- attributes contains more than one attribute with that nameClassFormatError
-
addInnerClassesAttributeEntry
Creates anInnerClasses
attribute if it does not exist, then adds the entry to theInnerClasses
attribute. -
getAnnotationsAttribute
@Nullable private ClassFile.AnnotationsAttribute getAnnotationsAttribute(boolean runtimeVisible, List<ClassFile.AttributeInfo> attributes) Finds theRuntime[In]visibleAnnotations
attribute in the attributes.- Returns:
null
if attributes constains no such attribute
-
getAnnotations
- Specified by:
getAnnotations
in interfaceAnnotatable
- Returns:
- The annotations on this element; an empty array iff there are no annotations
-
addAnnotationsAttributeEntry
public void addAnnotationsAttributeEntry(boolean runtimeVisible, String fieldDescriptor, Map<Short, ClassFile.ElementValue> elementValuePairs) Creates aRuntime[In]visibleAnnotations
attribute on the class (if it does not yet exist) and adds an entry to it.- Specified by:
addAnnotationsAttributeEntry
in interfaceAnnotatable
- Parameters:
elementValuePairs
- Maps element-name constant-pool-index (ClassFile.ConstantUtf8Info
) to element value
-
addAnnotationsAttributeEntry
private void addAnnotationsAttributeEntry(boolean runtimeVisible, String fieldDescriptor, Map<Short, ClassFile.ElementValue> elementValuePairs, List<ClassFile.AttributeInfo> target) Adds aRuntime[In]visibleAnnotations
attribute to the target (if it does not yet exist) and adds an entry to it.- Parameters:
elementValuePairs
- Maps "elemant_name_index" (ClassFile.ConstantUtf8Info
) to "element_value", see JVMS8 4.7.16
-
getThisClassName
- Returns:
- The fully qualified name of this class, e.g. "pkg1.pkg2.Outer$Inner"
-
setVersion
public void setVersion(short majorVersion, short minorVersion) Sets the major and minor class file version numbers (JVMS 4.1).ClassFile
declares a set of valid major-minor version number pairs, e.g.MAJOR_VERSION_JDK_1_6
andMINOR_VERSION_JDK_1_6
. -
getMajorVersion
public short getMajorVersion()- Returns:
- The current major class file version number
-
getMinorVersion
public short getMinorVersion()- Returns:
- The current minor class file version number
-
addConstantClassInfo
Returns the constant index number for a "CONSTANT_Class_info" structure to the class file. If the class hasn't been added before, adds it to the constant pool. Otherwise returns the constant number for that element of the pool.- See Also:
-
addConstantFieldrefInfo
Adds a "CONSTANT_Fieldref_info" structure to the class file.- See Also:
-
addConstantMethodrefInfo
Adds a "CONSTANT_Methodref_info" structure to the class file.- See Also:
-
addConstantInterfaceMethodrefInfo
Adds a "CONSTANT_InterfaceMethodref_info" structure to the class file.- See Also:
-
addConstantStringInfo
Adds a "CONSTANT_String_info" structure to the class file.- See Also:
-
addConstantIntegerInfo
public short addConstantIntegerInfo(int value) Adds a "CONSTANT_Integer_info" structure to the class file.- See Also:
-
addConstantFloatInfo
public short addConstantFloatInfo(float value) Adds a "CONSTANT_Float_info" structure to the class file.- See Also:
-
addConstantLongInfo
public short addConstantLongInfo(long value) Adds a "CONSTANT_Long_info" structure to the class file.- See Also:
-
addConstantDoubleInfo
public short addConstantDoubleInfo(double value) Adds a "CONSTANT_Double_info" structure to the class file.- See Also:
-
addConstantNameAndTypeInfo
Adds a "CONSTANT_NameAndType_info" structure to the class file.- See Also:
-
addConstantUtf8Info
Adds a "CONSTANT_Utf8_info" structure to the class file if no equal entry exists.- Returns:
- The index of the already existing or newly created entry
- See Also:
-
addConstantSifldInfo
Convenience method that adds a String, Integer, Float, Long or Double ConstantInfo. -
addToConstantPool
Adds an entry to the constant pool and returns its index, or, if an equal entry already exists in the constant pool, returns the index of that entry. -
addFieldInfo
public ClassFile.FieldInfo addFieldInfo(short accessFlags, String fieldName, String fieldTypeFd, @Nullable Object constantValue) Creates aClassFile.FieldInfo
and adds it to this class. The return value can be used e.g. to add attributes (Deprecated
, ...) to the field. -
addMethodInfo
public ClassFile.MethodInfo addMethodInfo(short accessFlags, String methodName, MethodDescriptor methodMd) Creates aClassFile.MethodInfo
and adds it to this class. The return value can be used e.g. to add attributes (Code
,Deprecated
,Exceptions
, ...) to the method. -
getConstantPoolInfo
- Returns:
- The (read-only) constant pool entry indexed by index
- Throws:
ClassFile.ClassFileException
- index is invalid
-
getConstantClassInfo
- Returns:
- The (read-only) constant class info indexed by index
-
getConstantFieldrefInfo
- Returns:
- The (read-only) constant fieldref info indexed by index
-
getConstantInterfaceMethodrefInfo
- Returns:
- The (read-only) constant interface methodref info indexed by index
-
getConstantInvokeDynamicInfo
- Returns:
- The (read-only) constant invoke dynamic info indexed by index
-
getConstantMethodHandleInfo
- Returns:
- The (read-only) constant method handle info indexed by index
-
getConstantMethodrefInfo
- Returns:
- The (read-only) constant methodref info indexed by index
-
getConstantMethodTypeInfo
- Returns:
- The (read-only) constant method type info indexed by index
-
getConstantNameAndTypeInfo
- Returns:
- The (read-only) constant name and type info indexed by index
-
getConstantUtf8Info
- Returns:
- The (read-only) constant utf8 info indexed by index
-
getConstantValuePoolInfo
- Returns:
- The (read-only) constant value pool info indexed by index
-
getConstantPoolSize
public int getConstantPoolSize()- Returns:
- The size of the constant pool
-
getConstantUtf8
Shorthand forgetConstantUtf8Info(index).s
.- Parameters:
index
- Index to aCONSTANT_Utf8_info
in the constant pool- Returns:
- The string represented by the structure
-
readLengthAndBytes
u4 length, u1[length]- Throws:
IOException
-
readShortArray
u2 length, u2[length]- Throws:
IOException
-
loadConstantPool
u2 constant_pool_count, constant_pool[constant_pool_count]- Throws:
IOException
-
loadFields
u2 fields_count, fields[fields_count]- Throws:
IOException
-
loadMethods
u2 methods_count, methods[methods_count]- Throws:
IOException
-
loadAttributes
u2 attributes_count, attributes[attributes_count]- Throws:
IOException
-
store
WritesClassFile
to anOutputStream
, in "class file" format.Notice that if an
IOException
is thrown, the class file is probably written incompletely and thus invalid. The calling method must take care of this situation, e.g. by closing the output stream and then deleting the file.- Throws:
IOException
-
storeConstantPool
private static void storeConstantPool(DataOutputStream dos, List<ClassFile.ConstantPoolInfo> constantPool) throws IOException u2 constant_pool_count, constant_pool[constant_pool_count - 1]- Throws:
IOException
-
storeShortArray
u2 count, u2[count]- Throws:
IOException
-
storeFields
private static void storeFields(DataOutputStream dos, List<ClassFile.FieldInfo> fieldInfos) throws IOException u2 fields_count, fields[fields_count]- Throws:
IOException
-
storeMethods
private static void storeMethods(DataOutputStream dos, List<ClassFile.MethodInfo> methodInfos) throws IOException u2 methods_count, methods[methods_count]- Throws:
IOException
-
storeAttributes
private static void storeAttributes(DataOutputStream dos, List<ClassFile.AttributeInfo> attributeInfos) throws IOException u2 attributes_count, attributes[attributes_count]- Throws:
IOException
-
getSourceResourceName
Constructs the name of a resource that could contain the source code of the class with the className.Notice that member types are declared inside a different type, so the relevant source file is that of the outermost declaring class.
- Parameters:
className
- Fully qualified class name, e.g."pkg1.pkg2.Outer$Inner"
- Returns:
- the name of the resource, e.g.
"pkg1/pkg2/Outer.java"
-
getClassFileResourceName
Constructs the name of a resource that could contain the class file of the class with the className.- Parameters:
className
- Fully qualified class name, e.g. "pkg1.pkg2.Outer$Inner"- Returns:
- the name of the resource, e.g. "pkg1/pkg2/Outer$Inner.class"
-
toByteArray
public byte[] toByteArray()Returns the byte code of thisClassFile
as a byte array. -
loadMethodInfo
- Throws:
IOException
-
loadAttribute
Loads one class file attribute. The returned object will be ofClassFile.AttributeInfo
-derived type, depending on the attribute's name; e.g. if the name of the attribute is"SourceFile"
, then the returned object will be of typeClassFile.SourceFileAttribute
.- Throws:
IOException
-
loadElementValue
- Throws:
IOException
-
newObjectVariableInfo
public ClassFile.StackMapTableAttribute.ObjectVariableInfo newObjectVariableInfo(String fieldDescriptor) -
newUninitializedVariableInfo
public ClassFile.StackMapTableAttribute.UninitializedVariableInfo newUninitializedVariableInfo(short offset) -
toString
-