javar.constantpool
Class ConstantPool

java.lang.Object
  |
  +--javar.constantpool.ConstantPool

public class ConstantPool
extends Object

This class represents the constant pool of a java class file

Author:
Ben Litchfield

Constructor Summary
ConstantPool()
          Default Constructor
ConstantPool(DataInputStream in)
          Default Constructor
 
Method Summary
 long addClass(String className)
          This will add an entry to the constant pool
 long addMethod(String className, String name, String type)
          This will add a new method to the pool
 long addNameAndType(String name, String type)
          This will add a name and type entry to the pool
 long addString(String entry)
          This will add an entry to the constant pool.
 long addUTF8(String entry)
          This will add an entry to the constant pool.
 long findUTF8(String string)
          This will find the index to the string, or -1 if it was not found.
 ConstantPoolEntry getEntry(long index)
          This will get an entry in the pool for you
 long getSize()
          This will return the number of entries that are contained
 boolean isReady(long index)
          This will tell you if the selected entry is ready to be read.
 Iterator listEntriesByType(byte code)
          This will get all entries in the constant pool based on a specific type.
 byte[] toBytes()
          This will get the constant pool as a set of bytes that are needed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConstantPool

public ConstantPool()
Default Constructor


ConstantPool

public ConstantPool(DataInputStream in)
             throws JavarParseException
Default Constructor

Method Detail

listEntriesByType

public Iterator listEntriesByType(byte code)
This will get all entries in the constant pool based on a specific type.

Parameters:
code - The type code used to search for entries.

getSize

public long getSize()
This will return the number of entries that are contained


getEntry

public ConstantPoolEntry getEntry(long index)
This will get an entry in the pool for you


isReady

public boolean isReady(long index)
This will tell you if the selected entry is ready to be read. This is only necessary while the pool is being created. If you read the first entry and it is a CONSTANT_Classref and it has as its data an index to a utf string, which might be at index 2, well we havn't read in number two yet, so the constant at number 2 will not be ready

Parameters:
index - The constant pool index
Returns:
A boolean flag if the constant pool entry has been initialized

toBytes

public byte[] toBytes()
               throws JavarIOException
This will get the constant pool as a set of bytes that are needed.

Returns:
the classfile bytes that represent this constant pool
JavarIOException

addString

public long addString(String entry)
This will add an entry to the constant pool.

Returns:
the index of that entry

addUTF8

public long addUTF8(String entry)
This will add an entry to the constant pool.

Returns:
the index of that entry

findUTF8

public long findUTF8(String string)
This will find the index to the string, or -1 if it was not found.

Parameters:
string - The string to find
Returns:
the index to the string

addClass

public long addClass(String className)
This will add an entry to the constant pool

Parameters:
className - The name of the class to add.
Returns:
the index where the class was stored.

addNameAndType

public long addNameAndType(String name,
                           String type)
This will add a name and type entry to the pool

Parameters:
name - The name
type - Thee type
Returns:
the index to this new entry

addMethod

public long addMethod(String className,
                      String name,
                      String type)
This will add a new method to the pool

Parameters:
className - The name of the class
name - The name of the method
type - Descriptor of the method
Returns:
the index to the method