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

public final Class ClassParser

extends Object
Class Inheritance
Imports
java.io.BufferedInputStream, .DataInput, .DataInputStream, .IOException, .InputStream, java.util.ArrayList, .List, org.apache.tomcat.util.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 static final int
private String
private ConstantPool
private final DataInput
private String[]
private static final String[]
private Annotations
private List<Annotations>
private String

Constructor Summary

AccessConstructor and Description
public
ClassParser(final InputStream
Input stream
inputStream
)

Parses class from the given stream.

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(boolean
false if processing a class
fieldOrMethod
)

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
BUFSIZEback to summary
private static final int BUFSIZE
classNameback to summary
private String className
constantPoolback to summary
private ConstantPool constantPool
dataInputStreamback to summary
private final DataInput dataInputStream
interfaceNamesback to summary
private String[] interfaceNames
INTERFACES_EMPTY_ARRAYback to summary
private static final String[] INTERFACES_EMPTY_ARRAY
runtimeVisibleAnnotationsback to summary
private Annotations runtimeVisibleAnnotations
runtimeVisibleFieldOrMethodAnnotationsback to summary
private List<Annotations> runtimeVisibleFieldOrMethodAnnotations
superclassNameback to summary
private String superclassName

Constructor Detail

ClassParserback to summary
public ClassParser(final InputStream inputStream)

Parses class from the given stream.

Parameters
inputStream:InputStream

Input stream

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(boolean fieldOrMethod) throws IOException, ClassFormatException

Reads information about the attributes of the class.

Parameters
fieldOrMethod:boolean

false if processing a 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, ClassFormatException

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