public class Attribute
extends java.lang.Object
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 and Description |
---|
Attribute(int nameIndex,
int length,
byte[] info)
Create a new attribute.
|
Modifier and Type | Method and Description |
---|---|
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.
|
public Attribute(int nameIndex, int length, byte[] info)
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.public Attribute getNext()
public void setNext(Attribute next)
public int getNameIndex()
public void setNameIndex(int nameIndex)
public int getLength()
public void setLength(int length)
public byte[] getInfo()
public void setInfo(byte[] info)
public static Attribute readTable(java.io.DataInputStream dataIn, ConstantPool cpool, AttributeHandler handler) throws java.io.IOException, ClassFileFormatException
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.
dataIn
- the input stream.cpool
- the Constant pool to use to resolve attribute names.handler
- An optional handler to delegate attribute processing
to.java.io.IOException
- If an I/O error occurs with the stream.ClassFileFormatException
- If malformed class data is
encountered.public static void writeTable(java.io.DataOutput dataOut, Attribute head) throws java.io.IOException
java.io.IOException
public static void writeAttribute(java.io.DataOutput dataOut, ConstantPool cp, java.lang.String name, int length, int data) throws java.io.IOException
java.io.IOException
public static void writeAttribute(java.io.DataOutput dout, ConstantPool cp, java.lang.String name, int length) throws java.io.IOException
java.io.IOException
public static int getTotalSize(Attribute attributes)
Copyright ? 2000-2003 Clarity Systems Group, LLC. All Rights Reserved.