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
appropriate 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
-
BUFSIZE
private static final int BUFSIZE- See Also:
-
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
-
-
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
- if an I/O error occurs.ClassFormatException
- if a class is malformed or cannot be interpreted as a class file
-
readAttributes
Reads information about the attributes of the class.- Throws:
IOException
- if an I/O error occurs.ClassFormatException
- if a class is malformed or cannot be interpreted as a class file
-
readClassInfo
Reads information about the class and its super class.- Throws:
IOException
- if an I/O error occurs.ClassFormatException
- if a class is malformed or cannot be interpreted as a class file
-
readConstantPool
Reads constant pool entries.- Throws:
IOException
- if an I/O error occurs.ClassFormatException
- if a class is malformed or cannot be interpreted as a class file
-
readFields
Reads information about the fields of the class, i.e., its variables.- Throws:
IOException
- if an I/O error occurs.ClassFormatException
- if a class is malformed or cannot be interpreted as a class file
-
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
- if an I/O error occurs.ClassFormatException
- if a class is malformed or cannot be interpreted as a class file
-
readInterfaces
Reads information about the interfaces implemented by this class.- Throws:
IOException
- if an I/O error occurs.ClassFormatException
- if a class is malformed or cannot be interpreted as a class file
-
readMethods
Reads information about the methods of the class.- Throws:
IOException
- if an I/O error occurs.ClassFormatException
- if a class is malformed or cannot be interpreted as a class file
-
readVersion
Reads major and minor version of compiler which created the file.- Throws:
IOException
- if an I/O error occurs.ClassFormatException
- if a class is malformed or cannot be interpreted as a class file
-