com.claritysys.jvm.classfile
Class Attribute

java.lang.Object
  extended by com.claritysys.jvm.classfile.Attribute

public class Attribute
extends java.lang.Object

An attribute list within a class, field, method, or code attribute.

Note that, in this implementation, each attribute in the classfile does not necessarily get read into an Attribute object: only the unrecognized ones do, so that a read classfile can be written again without loss of information. Recognized attributes are mapped to fields.


Constructor Summary
Attribute(int nameIndex, int length, byte[] info)
          Create a new attribute.
 
Method Summary
 byte[] getInfo()
           
 int getLength()
           
 int getNameIndex()
           
 Attribute getNext()
           
static int getTotalSize(Attribute attributes)
          Compute the total size of the attributes, including the 6 bytes of tag/length for each, plus the sum of the lengths.
static Attribute readTable(java.io.DataInputStream dataIn, ConstantPool cpool, AttributeHandler handler)
          Read attribute table from stream, returning a (possibly null) linked list of Attribute objects.
 void setInfo(byte[] info)
           
 void setLength(int length)
           
 void setNameIndex(int nameIndex)
           
 void setNext(Attribute next)
           
static void writeAttribute(java.io.DataOutput dout, ConstantPool cp, java.lang.String name, int length)
          Write an attribute, given its name, length, etc.
static void writeAttribute(java.io.DataOutput dataOut, ConstantPool cp, java.lang.String name, int length, int data)
          Write an attribute, given its name, length, etc.
static void writeTable(java.io.DataOutput dataOut, Attribute head)
          Write the attribute table to the stream, or nothing if the attribute is null.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Attribute

public Attribute(int nameIndex,
                 int length,
                 byte[] info)
Create a new attribute.

Parameters:
nameIndex - CpUtf8 index referencing name of attribute, such as "SourceFile" or "Code", etc.
length - length in bytes of the info[].
info - optional array of data relating to attribute.
Method Detail

getNext

public Attribute getNext()

setNext

public void setNext(Attribute next)

getNameIndex

public int getNameIndex()

setNameIndex

public void setNameIndex(int nameIndex)

getLength

public int getLength()

setLength

public void setLength(int length)

getInfo

public byte[] getInfo()

setInfo

public void setInfo(byte[] info)

readTable

public static Attribute readTable(java.io.DataInputStream dataIn,
                                  ConstantPool cpool,
                                  AttributeHandler handler)
                           throws java.io.IOException,
                                  ClassFileFormatException
Read attribute table from stream, returning a (possibly null) linked list of Attribute objects.

The caller can pass an AttributeHandler, which will be called to process each attribute as it is read from the stream. Unhandled attributes will be created as Attribute objects.

Parameters:
dataIn - the input stream.
cpool - the Constant pool to use to resolve attribute names.
handler - An optional handler to delegate attribute processing to.
Returns:
Linked list of Attribute, possibly null if there were no attributes or if the AttributeHandler processed them all.
Throws:
java.io.IOException - If an I/O error occurs with the stream.
ClassFileFormatException - If malformed class data is encountered.

writeTable

public static void writeTable(java.io.DataOutput dataOut,
                              Attribute head)
                       throws java.io.IOException
Write the attribute table to the stream, or nothing if the attribute is null.

Throws:
java.io.IOException

writeAttribute

public static void writeAttribute(java.io.DataOutput dataOut,
                                  ConstantPool cp,
                                  java.lang.String name,
                                  int length,
                                  int data)
                           throws java.io.IOException
Write an attribute, given its name, length, etc.

Throws:
java.io.IOException

writeAttribute

public static void writeAttribute(java.io.DataOutput dout,
                                  ConstantPool cp,
                                  java.lang.String name,
                                  int length)
                           throws java.io.IOException
Write an attribute, given its name, length, etc.

Throws:
java.io.IOException

getTotalSize

public static int getTotalSize(Attribute attributes)
Compute the total size of the attributes, including the 6 bytes of tag/length for each, plus the sum of the lengths.



Copyright ? 2000-2003 Clarity Systems Group, LLC. All Rights Reserved.