Jode 1.90-CVS
Build Aug 6, 2004

net.sf.jode.bytecode
Class BinaryInfo

java.lang.Object
  extended bynet.sf.jode.bytecode.BinaryInfo
Direct Known Subclasses:
BasicBlocks, ClassInfo, FieldInfo, MethodInfo

public class BinaryInfo
extends java.lang.Object

Represents a container for user specified attributes.

Java bytecode is extensible: Classes, Methods and Fields may have any number of attributes. Every attribute has a name and some unformatted data.

There are some predefined attributes, even the Code of a Method is an attribute. These predefined attributes are all handled by this package as appropriate. These methods are only useful for non standard attributes.

You can provide new attributes by overriding the protected methods of this class. This makes it possible to use constant pool entries in the attributes.

Another possibility is to add the attributes with the public method. This way you don't need to extend the classes, but you can't use a constant pool for the contents of the attributes. One possible application of this are installation classes. These classes have a special attribute containing a zip archive of the files that should be installed. There are other possible uses, e.g. putting native machine code for some architectures into the class.

Author:
Jochen Hoenicke

Field Summary
static int ACC_ABSTRACT
          The bit mask representing abstract modifier.
static int ACC_ANNOTATION
          The bit mask representing annotation classes.
static int ACC_BRIDGE
          The bit mask representing synthetic bridge method.
static int ACC_ENUM
          The bit mask representing enum fields.
static int ACC_FINAL
          The bit mask representing final modifier.
static int ACC_INTERFACE
          The bit mask representing interfaces.
static int ACC_NATIVE
          The bit mask representing native methods.
static int ACC_PRIVATE
          The bit mask representing private modifier.
static int ACC_PROTECTED
          The bit mask representing protected modifier.
static int ACC_PUBLIC
          The bit mask representing public modifier.
static int ACC_STATIC
          The bit mask representing static modifier.
static int ACC_STRICT
          The bit mask representing strictfp modifier.
static int ACC_SUPER
          The bit mask representing the ACC_SUPER modifier for classes.
static int ACC_SYNTHETIC
          The bit mask representing synthetic fields/methods and classes.
static int ACC_TRANSIENT
          The bit mask representing transient fields.
static int ACC_VARARGS
          The bit mask representing varargs methods.
static int ACC_VOLATILE
          The bit mask representing volatile modifier for fields.
 
Constructor Summary
BinaryInfo()
           
 
Method Summary
 void addAttribute(java.lang.String name, byte[] contents)
          Adds a new non standard attribute or replaces an old one with the same name.
protected  void drop(int keep)
          Drops information from this info.
 byte[] findAttribute(java.lang.String name)
          Finds a non standard attribute with the given name.
protected  int getAttributeCount()
          Returns the number of attributes of this class.
 java.util.Iterator getAttributes()
          Gets all non standard attributes.
protected  int getAttributeSize()
          Gets the total length of all attributes in this binary info.
protected  void prepareAttributes(GrowableConstantPool gcp)
          Prepare writing your attributes.
protected  void readAttribute(java.lang.String name, int length, ConstantPool constantPool, java.io.DataInputStream input, int howMuch)
          Reads in an attributes of this class.
 void removeAllAttributes()
          Removes all non standard attributes.
 byte[] removeAttribute(java.lang.String name)
          Removes a non standard attributes.
protected  void writeAttributes(GrowableConstantPool constantPool, java.io.DataOutputStream output)
          Writes the attributes to the output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ACC_PUBLIC

public static int ACC_PUBLIC
The bit mask representing public modifier.


ACC_PRIVATE

public static int ACC_PRIVATE
The bit mask representing private modifier.


ACC_PROTECTED

public static int ACC_PROTECTED
The bit mask representing protected modifier.


ACC_STATIC

public static int ACC_STATIC
The bit mask representing static modifier.


ACC_FINAL

public static int ACC_FINAL
The bit mask representing final modifier.


ACC_SUPER

public static int ACC_SUPER
The bit mask representing the ACC_SUPER modifier for classes. This is a special modifier that only has historic meaning. Every class should have this set.


ACC_VOLATILE

public static int ACC_VOLATILE
The bit mask representing volatile modifier for fields.


ACC_BRIDGE

public static int ACC_BRIDGE
The bit mask representing synthetic bridge method. This is used when a non-generic method overrides a generic method of super class/interface.


ACC_TRANSIENT

public static int ACC_TRANSIENT
The bit mask representing transient fields.


ACC_VARARGS

public static int ACC_VARARGS
The bit mask representing varargs methods.


ACC_ENUM

public static int ACC_ENUM
The bit mask representing enum fields.


ACC_NATIVE

public static int ACC_NATIVE
The bit mask representing native methods.


ACC_INTERFACE

public static int ACC_INTERFACE
The bit mask representing interfaces.


ACC_ABSTRACT

public static int ACC_ABSTRACT
The bit mask representing abstract modifier.


ACC_ANNOTATION

public static int ACC_ANNOTATION
The bit mask representing annotation classes.


ACC_STRICT

public static int ACC_STRICT
The bit mask representing strictfp modifier.


ACC_SYNTHETIC

public static int ACC_SYNTHETIC
The bit mask representing synthetic fields/methods and classes.

Constructor Detail

BinaryInfo

public BinaryInfo()
Method Detail

readAttribute

protected void readAttribute(java.lang.String name,
                             int length,
                             ConstantPool constantPool,
                             java.io.DataInputStream input,
                             int howMuch)
                      throws java.io.IOException
Reads in an attributes of this class. Overwrite this method if you want to handle your own attributes. If you don't know how to handle an attribute call this method for the super class.

Parameters:
name - the attribute name.
length - the length of the attribute.
constantPool - the constant pool of the class.
input - a data input stream where you can read the attribute from. It will protect you to read more over the attribute boundary.
howMuch - the constant that was given to the ClassInfo.load(int) function when loading this class.
Throws:
java.io.IOException

drop

protected void drop(int keep)
Drops information from this info. Override this to drop your own info and don't forget to call the method of the super class.

Parameters:
keep - the constant representing how much information we should keep (see ClassInfo.load(int)).

getAttributeCount

protected int getAttributeCount()
Returns the number of attributes of this class. Overwrite this method if you want to add your own attributes by providing a writeAttributes method. You should call this method for the super class and add the number of your own attributes to the returned value.

Returns:
the number of attributes of this class.

prepareAttributes

protected void prepareAttributes(GrowableConstantPool gcp)
Prepare writing your attributes. Overwrite this method if you want to add your own attributes, which need constants on the class pool. Add the necessary constants to the constant pool and call this method for the super class.

Parameters:
gcp - The growable constant pool.

writeAttributes

protected void writeAttributes(GrowableConstantPool constantPool,
                               java.io.DataOutputStream output)
                        throws java.io.IOException

Writes the attributes to the output stream. Overwrite this method if you want to add your own attributes. All constants you need from the growable constant pool must have been previously registered by the prepareAttributes(net.sf.jode.bytecode.GrowableConstantPool) method. This method must not add new constants to the pool

First call the method of the super class. Afterwrites write each of your own attributes including the attribute header (name and length entry).

Parameters:
constantPool - The growable constant pool, which is not growable anymore (see above).
output - the data output stream. You must write exactly as many bytes to it as you have told with the getAttributeSize() method.
Throws:
java.io.IOException

getAttributeSize

protected int getAttributeSize()
Gets the total length of all attributes in this binary info. Overwrite this method if you want to add your own attributes and add the size of your attributes to the value returned by the super class.
Currently you only need to write this if you extend BasicBlocks.

Returns:
the total length of all attributes, including their headers and the "number of attributes" field.

findAttribute

public byte[] findAttribute(java.lang.String name)
Finds a non standard attribute with the given name. You don't have access to the constant pool. If you need the pool don't use this method but extend this class and override readAttribute method.

Parameters:
name - the name of the attribute.
Returns:
the contents of the attribute, null if not found.
See Also:
readAttribute(java.lang.String, int, net.sf.jode.bytecode.ConstantPool, java.io.DataInputStream, int)

getAttributes

public java.util.Iterator getAttributes()
Gets all non standard attributes.

Returns:
an iterator for all attributes. The values returned by the next() method of the iterator are of Map.Entry type. The key of the entry is the name of the attribute, while the values are the byte[] contents.
See Also:
findAttribute(java.lang.String)

addAttribute

public void addAttribute(java.lang.String name,
                         byte[] contents)
Adds a new non standard attribute or replaces an old one with the same name. If it already exists, it will be overwritten. Note that there's now way to correlate the contents with a constant pool. If you need that extend this class and override the methods getAttributeCount(), prepareAttributes(net.sf.jode.bytecode.GrowableConstantPool), writeAttributes(net.sf.jode.bytecode.GrowableConstantPool, java.io.DataOutputStream), and getAttributeSize().

Parameters:
name - the name of the attribute.
contents - the new contens.

removeAttribute

public byte[] removeAttribute(java.lang.String name)
Removes a non standard attributes.

Parameters:
name - the name of the attribute.
Returns:
the old contents of the attribute.

removeAllAttributes

public void removeAllAttributes()
Removes all non standard attributes.


Jode 1.90-CVS
Build Aug 6, 2004

Copyright © 1998-2004 by Jochen Hoenicke.