org.apache.bcel.classfile

Class ClassParser

public final class ClassParser extends Object

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.

Version: $Id: ClassParser.java 386056 2006-03-15 11:31:56Z tcurdt $

Author: M. Dahm

Field Summary
intaccess_flags
Attribute[]attributes
static intBUFSIZE
intclass_name_index
ConstantPoolconstant_pool
Field[]fields
DataInputStreamfile
booleanfileOwned
Stringfile_name
int[]interfaces
booleanis_zip
intmajor
Method[]methods
intminor
intsuperclass_name_index
Stringzip_file
Constructor Summary
ClassParser(InputStream file, String file_name)
Parse class from the given stream.
ClassParser(String file_name)
Parse class from given .class file.
ClassParser(String zip_file, String file_name)
Parse class from given .class file in a ZIP-archive
Method Summary
JavaClassparse()
Parse the given Java class file and return an object that represents the contained data, i.e., constants, methods, fields and commands.
voidreadAttributes()
Read information about the attributes of the class.
voidreadClassInfo()
Read information about the class and its super class.
voidreadConstantPool()
Read constant pool entries.
voidreadFields()
Read information about the fields of the class, i.e., its variables.
voidreadID()
Check whether the header of the file is ok.
voidreadInterfaces()
Read information about the interfaces implemented by this class.
voidreadMethods()
Read information about the methods of the class.
voidreadVersion()
Read major and minor version of compiler which created the file.

Field Detail

access_flags

private int access_flags

attributes

private Attribute[] attributes

BUFSIZE

private static final int BUFSIZE

class_name_index

private int class_name_index

constant_pool

private ConstantPool constant_pool

fields

private Field[] fields

file

private DataInputStream file

fileOwned

private boolean fileOwned

file_name

private String file_name

interfaces

private int[] interfaces

is_zip

private boolean is_zip

major

private int major

methods

private Method[] methods

minor

private int minor

superclass_name_index

private int superclass_name_index

zip_file

private String zip_file

Constructor Detail

ClassParser

public ClassParser(InputStream file, String file_name)
Parse class from the given stream.

Parameters: file Input stream file_name File name

ClassParser

public ClassParser(String file_name)
Parse class from given .class file.

Parameters: file_name file name

ClassParser

public ClassParser(String zip_file, String file_name)
Parse class from given .class file in a ZIP-archive

Parameters: zip_file zip file name file_name file name

Method Detail

parse

public JavaClass parse()
Parse 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

private final void readAttributes()
Read information about the attributes of the class.

Throws: IOException ClassFormatException

readClassInfo

private final void readClassInfo()
Read information about the class and its super class.

Throws: IOException ClassFormatException

readConstantPool

private final void readConstantPool()
Read constant pool entries.

Throws: IOException ClassFormatException

readFields

private final void readFields()
Read information about the fields of the class, i.e., its variables.

Throws: IOException ClassFormatException

readID

private final void readID()
Check 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

private final void readInterfaces()
Read information about the interfaces implemented by this class.

Throws: IOException ClassFormatException

readMethods

private final void readMethods()
Read information about the methods of the class.

Throws: IOException ClassFormatException

readVersion

private final void readVersion()
Read major and minor version of compiler which created the file.

Throws: IOException ClassFormatException