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 int
private Attribute[]
private static final int
private int
private ConstantPool
private DataInputStream
private Field[]
private final String
private final boolean
private int[]
private final boolean
private int
private Method[]
private int
private int
private String
-
Constructor Summary
ConstructorsConstructorDescriptionClassParser
(InputStream inputStream, String fileName) Parses class from the given stream.ClassParser
(String fileName) Parses class from given .class file.ClassParser
(String zipFile, String fileName) 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 void
Reads information about the attributes of the class.private void
Reads information about the class and its super class.private void
Reads constant pool entries.private void
Reads information about the fields of the class, i.e., its variables.private void
readID()
Checks whether the header of the file is ok.private void
Reads information about the interfaces implemented by this class.private void
Reads information about the methods of the class.private void
Reads major and minor version of compiler which created the file.
-
Field Details
-
dataInputStream
-
fileOwned
private final boolean fileOwned -
fileName
-
zipFile
-
classNameIndex
private int classNameIndex -
superclassNameIndex
private int superclassNameIndex -
major
private int major -
minor
private int minor -
accessFlags
private int accessFlags -
interfaces
private int[] interfaces -
constantPool
-
fields
-
methods
-
attributes
-
isZip
private final boolean isZip -
BUFSIZE
private static final int BUFSIZE- See Also:
-
-
Constructor Details
-
ClassParser
Parses class from the given stream.- Parameters:
inputStream
- Input streamfileName
- File name
-
ClassParser
Parses class from given .class file.- Parameters:
fileName
- file name
-
ClassParser
Parses class from given .class file in a ZIP-archive- Parameters:
zipFile
- zip file namefileName
- 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:
IOException
ClassFormatException
-
readAttributes
Reads information about the attributes of the class.- Throws:
IOException
ClassFormatException
-
readClassInfo
Reads information about the class and its super class.- Throws:
IOException
ClassFormatException
-
readConstantPool
Reads constant pool entries.- Throws:
IOException
ClassFormatException
-
readFields
Reads information about the fields of the class, i.e., its variables.- Throws:
IOException
ClassFormatException
-
readID
Checks whether the header of the file is ok. Of course, this has to be the first action on successive file reads.- Throws:
IOException
ClassFormatException
-
readInterfaces
Reads information about the interfaces implemented by this class.- Throws:
IOException
ClassFormatException
-
readMethods
Reads information about the methods of the class.- Throws:
IOException
ClassFormatException
-
readVersion
Reads major and minor version of compiler which created the file.- Throws:
IOException
ClassFormatException
-