ej-technologies

org.gjt.jclasslib.structures
Class AttributeInfo

java.lang.Object
  extended byorg.gjt.jclasslib.structures.AbstractStructure
      extended byorg.gjt.jclasslib.structures.AbstractStructureWithAttributes
          extended byorg.gjt.jclasslib.structures.AttributeInfo
Direct Known Subclasses:
CodeAttribute, ConstantValueAttribute, DeprecatedAttribute, ExceptionsAttribute, InnerClassesAttribute, LineNumberTableAttribute, LocalVariableTableAttribute, SourceFileAttribute, SyntheticAttribute

public class AttributeInfo
extends AbstractStructureWithAttributes

Base class for all attribute structures in the attribute package.

Version:
$Revision: 1.5 $ $Date: 2003/08/18 07:52:54 $
Author:
Ingo Kegel

Field Summary
static String SYSTEM_PROPERTY_SKIP_ATTRIBUTES
          Set this JVM System property to true to skip reading of all attributes.
 
Fields inherited from class org.gjt.jclasslib.structures.AbstractStructureWithAttributes
attributes
 
Fields inherited from class org.gjt.jclasslib.structures.AbstractStructure
classFile, debug, SYSTEM_PROPERTY_DEBUG
 
Constructor Summary
protected AttributeInfo()
          Constructor.
 
Method Summary
static AttributeInfo createOrSkip(DataInput in, ClassFile classFile)
          Factory method for creating AttributeInfo structures.
 int getAttributeLength()
          Get the length of this attribute as a number of bytes.
 int getAttributeNameIndex()
          Get the constant pool index for the name of the attribute.
 byte[] getInfo()
          Get the raw bytes of the attribute.
 String getName()
          Get the name of the attribute.
 void read(DataInput in)
          Read this structure from the given DataInput.
 void setAttributeNameIndex(int attributeNameIndex)
          Set the constant pool index for the name of the attribute.
 void setInfo(byte[] info)
          Set the raw bytes of the attribute.
 void write(DataOutput out)
          Write this structure to the given DataOutput.
 
Methods inherited from class org.gjt.jclasslib.structures.AbstractStructureWithAttributes
findAttribute, getAttributes, getTotalAttributesLength, readAttributes, setAttributes, writeAttributes
 
Methods inherited from class org.gjt.jclasslib.structures.AbstractStructure
debug, getClassFile, getDebug, getLength, printAccessFlags, printAccessFlagsVerbose, printBytes, setClassFile, setDebug
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SYSTEM_PROPERTY_SKIP_ATTRIBUTES

public static final String SYSTEM_PROPERTY_SKIP_ATTRIBUTES
Set this JVM System property to true to skip reading of all attributes. Some class file operations may fail in this case.

See Also:
Constant Field Values
Constructor Detail

AttributeInfo

protected AttributeInfo()
Constructor.

Method Detail

createOrSkip

public static AttributeInfo createOrSkip(DataInput in,
                                         ClassFile classFile)
                                  throws InvalidByteCodeException,
                                         IOException
Factory method for creating AttributeInfo structures.

An AttributeInfo of the appropriate subtype from the attributes package is created unless the type of the attribute is unknown in which case an instance of AttributeInfo is returned.

Attributes are skipped if the environment variable SYSTEM_PROPERTY_SKIP_ATTRIBUTES is set to true.

Parameters:
in - the DataInput from which to read the AttributeInfo structure
classFile - the parent class file of the structure to be created
Returns:
the new AttributeInfo structure
Throws:
InvalidByteCodeException - if the byte code is invalid
IOException - if an exception occurs with the DataInput

getAttributeNameIndex

public int getAttributeNameIndex()
Get the constant pool index for the name of the attribute.

Returns:
the index

setAttributeNameIndex

public void setAttributeNameIndex(int attributeNameIndex)
Set the constant pool index for the name of the attribute.

Parameters:
attributeNameIndex - the new index

getInfo

public byte[] getInfo()
Get the raw bytes of the attribute.

Is non-null only if attribute is of unknown type.

Returns:
the byte array

setInfo

public void setInfo(byte[] info)
Set the raw bytes of the attribute.

Works only if attribute is an instance of AttributeInfo.

Parameters:
info - the new byte array

getName

public String getName()
               throws InvalidByteCodeException
Get the name of the attribute.

Returns:
the name
Throws:
InvalidByteCodeException - if the byte code is invalid

read

public void read(DataInput in)
          throws InvalidByteCodeException,
                 IOException
Description copied from class: AbstractStructure
Read this structure from the given DataInput.

Excpects DataInput to be in JVM class file format and just before a structure of this kind. No look ahead parsing since the class file format is deterministic.

Overrides:
read in class AbstractStructure
Parameters:
in - the DataInput from which to read
Throws:
InvalidByteCodeException - if the byte code is invalid
IOException - if an exception occurs with the DataInput

write

public void write(DataOutput out)
           throws InvalidByteCodeException,
                  IOException
Description copied from class: AbstractStructure
Write this structure to the given DataOutput.

The written bytes are in JVM class file format.

Overrides:
write in class AbstractStructure
Parameters:
out - the DataOutput to which to write
Throws:
InvalidByteCodeException - if the structure is internally inconsistent
IOException - if an exception occurs with the DataOutput

getAttributeLength

public int getAttributeLength()
Get the length of this attribute as a number of bytes.

Returns:
the length

ej-technologies