Top Description Fields Constructors Methods
org.apache.bcel.classfile

public final Class ClassParser

extends Object
Class Inheritance
Imports
java.io.BufferedInputStream, .DataInputStream, .FileInputStream, .IOException, .InputStream, java.util.zip.ZipEntry, .ZipFile, org.apache.bcel.Const

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

Modifier and TypeField and Description
private 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

AccessConstructor and Description
public
ClassParser(final InputStream
Input stream
inputStream
,
final String
File name
fileName
)

Parses class from the given stream.

public
ClassParser(final String
file name
fileName
)

Parses class from given .class file.

public
ClassParser(final String
ZIP file name
zipFile
,
final String
file name
fileName
)

Parses class from given .class file in a ZIP-archive

Method Summary

Modifier and TypeMethod and Description
public JavaClass

Returns:

Class object representing the parsed class file
parse
()

Parses the given Java class file and return an object that represents the contained data, i.e., constants, methods, fields and commands.

private void
readAttributes()

Reads information about the attributes of the class.

private void
readClassInfo()

Reads information about the class and its super class.

private void
readConstantPool()

Reads constant pool entries.

private void
readFields()

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
readInterfaces()

Reads information about the interfaces implemented by this class.

private void
readMethods()

Reads information about the methods of the class.

private void
readVersion()

Reads major and minor version of compiler which created the file.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

accessFlagsback to summary
private int accessFlags
attributesback to summary
private Attribute[] attributes
BUFSIZEback to summary
private static final int BUFSIZE
classNameIndexback to summary
private int classNameIndex
constantPoolback to summary
private ConstantPool constantPool
dataInputStreamback to summary
private DataInputStream dataInputStream
fieldsback to summary
private Field[] fields
fileNameback to summary
private final String fileName
fileOwnedback to summary
private final boolean fileOwned
interfacesback to summary
private int[] interfaces
isZipback to summary
private final boolean isZip
majorback to summary
private int major
methodsback to summary
private Method[] methods
minorback to summary
private int minor
superclassNameIndexback to summary
private int superclassNameIndex
zipFileback to summary
private String zipFile

Constructor Detail

ClassParserback to summary
public ClassParser(final InputStream inputStream, final String fileName)

Parses class from the given stream.

Parameters
inputStream:InputStream

Input stream

fileName:String

File name

ClassParserback to summary
public ClassParser(final String fileName)

Parses class from given .class file.

Parameters
fileName:String

file name

ClassParserback to summary
public ClassParser(final String zipFile, final String fileName)

Parses class from given .class file in a ZIP-archive

Parameters
zipFile:String

ZIP file name

fileName:String

file name

Method Detail

parseback to summary
public JavaClass parse() throws IOException, ClassFormatException

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:JavaClass

Class object representing the parsed class file

Exceptions
IOException:
if an I/O error occurs.
ClassFormatException:
if a class is malformed or cannot be interpreted as a class file
readAttributesback to summary
private void readAttributes() throws IOException, ClassFormatException

Reads information about the attributes of the class.

Exceptions
IOException:
if an I/O error occurs.
ClassFormatException:
if a class is malformed or cannot be interpreted as a class file
readClassInfoback to summary
private void readClassInfo() throws IOException, ClassFormatException

Reads information about the class and its super class.

Exceptions
IOException:
if an I/O error occurs.
ClassFormatException:
if a class is malformed or cannot be interpreted as a class file
readConstantPoolback to summary
private void readConstantPool() throws IOException, ClassFormatException

Reads constant pool entries.

Exceptions
IOException:
if an I/O error occurs.
ClassFormatException:
if a class is malformed or cannot be interpreted as a class file
readFieldsback to summary
private void readFields() throws IOException, ClassFormatException

Reads information about the fields of the class, i.e., its variables.

Exceptions
IOException:
if an I/O error occurs.
ClassFormatException:
if a class is malformed or cannot be interpreted as a class file
readIDback to summary
private void readID() throws IOException, ClassFormatException

Checks whether the header of the file is ok. Of course, this has to be the first action on successive file reads.

Exceptions
IOException:
if an I/O error occurs.
ClassFormatException:
if a class is malformed or cannot be interpreted as a class file
readInterfacesback to summary
private void readInterfaces() throws IOException, ClassFormatException

Reads information about the interfaces implemented by this class.

Exceptions
IOException:
if an I/O error occurs.
ClassFormatException:
if a class is malformed or cannot be interpreted as a class file
readMethodsback to summary
private void readMethods() throws IOException

Reads information about the methods of the class.

Exceptions
IOException:
if an I/O error occurs.
ClassFormatException:
if a class is malformed or cannot be interpreted as a class file
readVersionback to summary
private void readVersion() throws IOException, ClassFormatException

Reads major and minor version of compiler which created the file.

Exceptions
IOException:
if an I/O error occurs.
ClassFormatException:
if a class is malformed or cannot be interpreted as a class file