Package org.apache.bcel.classfile
Class ClassParser
java.lang.Object
org.apache.bcel.classfile.ClassParser
Wrapper class that parses a given Java .class file. The method parse returns a
JavaClass object on success. When an I/O error or an
inconsistency occurs an appropiate exception is propagated back to
the caller.
The structure and the names comply, except for a few conveniences,
exactly with the
JVM specification 1.0. See this paper for
further details about the structure of a bytecode file.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate intprivate Attribute[]private static final intprivate intprivate ConstantPoolprivate DataInputStreamprivate Field[]private final Stringprivate final booleanprivate int[]private final booleanprivate intprivate Method[]private intprivate intprivate String -
Constructor Summary
ConstructorsConstructorDescriptionClassParser(InputStream inputStream, String file_name) Parses class from the given stream.ClassParser(String file_name) Parses class from given .class file.ClassParser(String zip_file, String file_name) Parses class from given .class file in a ZIP-archive -
Method Summary
Modifier and TypeMethodDescriptionparse()Parses the given Java class file and return an object that represents the contained data, i.e., constants, methods, fields and commands.private voidReads information about the attributes of the class.private voidReads information about the class and its super class.private voidReads constant pool entries.private voidReads information about the fields of the class, i.e., its variables.private voidreadID()Checks whether the header of the file is ok.private voidReads information about the interfaces implemented by this class.private voidReads information about the methods of the class.private voidReads major and minor version of compiler which created the file.
-
Field Details
-
dataInputStream
-
fileOwned
private final boolean fileOwned -
file_name
-
zip_file
-
class_name_index
private int class_name_index -
superclass_name_index
private int superclass_name_index -
major
private int major -
minor
private int minor -
access_flags
private int access_flags -
interfaces
private int[] interfaces -
constant_pool
-
fields
-
methods
-
attributes
-
is_zip
private final boolean is_zip -
BUFSIZE
private static final int BUFSIZE- See Also:
-
-
Constructor Details
-
ClassParser
Parses class from the given stream.- Parameters:
inputStream- Input streamfile_name- File name
-
ClassParser
Parses class from given .class file.- Parameters:
file_name- file name
-
ClassParser
Parses class from given .class file in a ZIP-archive- Parameters:
zip_file- zip file namefile_name- file name
-
-
Method Details
-
parse
Parses the given Java class file and return an object that represents the contained data, i.e., constants, methods, fields and commands. A ClassFormatException is raised, if the file is not a valid .class file. (This does not include verification of the byte code as it is performed by the java interpreter).- Returns:
- Class object representing the parsed class file
- Throws:
IOExceptionClassFormatException
-
readAttributes
Reads information about the attributes of the class.- Throws:
IOExceptionClassFormatException
-
readClassInfo
Reads information about the class and its super class.- Throws:
IOExceptionClassFormatException
-
readConstantPool
Reads constant pool entries.- Throws:
IOExceptionClassFormatException
-
readFields
Reads information about the fields of the class, i.e., its variables.- Throws:
IOExceptionClassFormatException
-
readID
Checks whether the header of the file is ok. Of course, this has to be the first action on successive file reads.- Throws:
IOExceptionClassFormatException
-
readInterfaces
Reads information about the interfaces implemented by this class.- Throws:
IOExceptionClassFormatException
-
readMethods
Reads information about the methods of the class.- Throws:
IOExceptionClassFormatException
-
readVersion
Reads major and minor version of compiler which created the file.- Throws:
IOExceptionClassFormatException
-