All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class futils.utils.ClassFile

java.lang.Object
   |
   +----futils.utils.ClassFile

public class ClassFile
extends java.lang.Object
This class is used to manipulate Java class files in strange and mysterious ways. Usage it typically to feed it an array of bytes that are a class file, manipulate the class, then convert the class back into bytes, and feed the final result to defineClass().

Version:
1.6, 19 Aug 1995
Author:
Chuck McManis
See Also:
FieldInfo

Variable Index

 o ACC_ABSTRACT
 o ACC_FINAL
 o ACC_INTERFACE
 o ACC_NATIVE
 o ACC_PRIVATE
 o ACC_PROTECTED
 o ACC_PUBLIC
 o ACC_STATIC
 o ACC_SYNCHRONIZED
 o ACC_THREADSAFE
 o ACC_TRANSIENT
 o accessFlags
 o attributes
 o constantPool
 o debug
 o dumpConstants
 o fields
 o interfaces
 o isValidClass
 o magic
 o majorVersion
 o methods
 o minorVersion
 o superClass
 o thisClass

Constructor Index

 o ClassFile()

Method Index

 o accessString(short)
Returns a string that represents what the access flags are set for.
 o addAttribute(AttributeInfo)
Add a new optional class Attribute.
 o addConstantPoolItem(ConstantPoolInfo)
Add a single constant pool item and return its index.
 o addConstantPoolItems(ConstantPoolInfo[])
Add some items to the constant pool.
 o deleteMethod(String, String)
Delete a named method from this class.
 o display(PrintStream)
Write out a text version of this class.
 o getAttribute(String)
Return the attribute named 'name' from the class file.
 o getClassName()
 o getConstantPoolItem(short)
Return a constant pool item from this class.
 o getConstantRef(short)
 o mapClass(String, String)
Map occurences of class oldClass to occurrences of class newClass.
 o mapPackage(String, String)
Map occurences of package oldPackage to package newPackage.
 o nextSig(String)
Returns the next signature from a string of concatenated signatures.
 o printClassName(String)
Print the name of a class in "canonical form"
 o read(InputStream)
Read a class from InputStream in.
 o toString()
The boring version of display().
 o typeString(String, String)
Takes a type signature and a string representing a variable name and returns a declaration for that variable name.
 o write(OutputStream)
Write the class out as a stream of bytes to the output stream.

Variables

 o magic
 int magic
 o majorVersion
 short majorVersion
 o minorVersion
 short minorVersion
 o constantPool
 futils.utils.ConstantPoolInfo constantPool[]
 o accessFlags
 short accessFlags
 o thisClass
 futils.utils.ConstantPoolInfo thisClass
 o superClass
 futils.utils.ConstantPoolInfo superClass
 o interfaces
 futils.utils.ConstantPoolInfo interfaces[]
 o fields
 futils.utils.FieldInfo fields[]
 o methods
 futils.utils.MethodInfo methods[]
 o attributes
 futils.utils.AttributeInfo attributes[]
 o isValidClass
 boolean isValidClass
 o ACC_PUBLIC
 public static final int ACC_PUBLIC
 o ACC_PRIVATE
 public static final int ACC_PRIVATE
 o ACC_PROTECTED
 public static final int ACC_PROTECTED
 o ACC_STATIC
 public static final int ACC_STATIC
 o ACC_FINAL
 public static final int ACC_FINAL
 o ACC_SYNCHRONIZED
 public static final int ACC_SYNCHRONIZED
 o ACC_THREADSAFE
 public static final int ACC_THREADSAFE
 o ACC_TRANSIENT
 public static final int ACC_TRANSIENT
 o ACC_NATIVE
 public static final int ACC_NATIVE
 o ACC_INTERFACE
 public static final int ACC_INTERFACE
 o ACC_ABSTRACT
 public static final int ACC_ABSTRACT
 o debug
 public boolean debug
 o dumpConstants
 public boolean dumpConstants

Constructors

 o ClassFile
 public ClassFile()

Methods

 o read
 public boolean read(java.io.InputStream in) throws java.io.IOException
Read a class from InputStream in.

 o write
 public void write(java.io.OutputStream out) throws java.io.IOException, java.lang.Exception
Write the class out as a stream of bytes to the output stream. Generally you will read a class file, manipulate it in some way, and then write it out again before passing it to defineClass in some class loader.

 o accessString
 public static java.lang.String accessString(short flags)
Returns a string that represents what the access flags are set for. So 0x14 returns "public final "

 o typeString
 public static java.lang.String typeString(java.lang.String typeString,
                                           java.lang.String varName)
Takes a type signature and a string representing a variable name and returns a declaration for that variable name. For example, passing this the strings "[B" and "myArray" will return the string "byte myArray[]"

 o nextSig
 public static java.lang.String nextSig(java.lang.String sig)
Returns the next signature from a string of concatenated signatures. For example if the signature was "[BII", this method would return "II"

 o printClassName
 private java.lang.String printClassName(java.lang.String s)
Print the name of a class in "canonical form"

 o getClassName
 public java.lang.String getClassName()
 o toString
 public java.lang.String toString()
The boring version of display().

Overrides:
toString in class java.lang.Object
 o display
 public void display(java.io.PrintStream ps) throws java.lang.Exception
Write out a text version of this class.

 o getConstantRef
 public futils.utils.ConstantPoolInfo getConstantRef(short index)
 o addConstantPoolItem
 public short addConstantPoolItem(futils.utils.ConstantPoolInfo item) throws java.lang.Exception
Add a single constant pool item and return its index. If the item is already in the pool then the index of the preexisting item is returned. Thus you cannot assume that a pointer to your item will be useful.

 o addConstantPoolItems
 public void addConstantPoolItems(futils.utils.ConstantPoolInfo items[])
Add some items to the constant pool. This is used to add new items to the constant pool. The items references in arg1 and arg2 are expected to be valid pointers (if necessary). Pruning is done to prevent adding redundant items to the list and to preserve string space. The algorithm is simple, first identify pool items containing constants in the list of items to be added that are already in the constant pool. If any are found to already exist, change the pointers in the non-constant items to point to the ones in the pool rather than the ones in the list. Next check to see if any of the non-constant items are already in the pool and if so fix up the others in the list to point to the ones in the pool. Finally, add any items (there must be at least one) from the item list that aren't already in the pool, all of the pointers will already be fixed. NOTE: Since constants in the constant pool may be referenced inside the opaque portion of attributes the constant table cannot be re-ordered, only extended.

 o addAttribute
 public void addAttribute(futils.utils.AttributeInfo newAttribute)
Add a new optional class Attribute. Items is an array of constant pool items that are first added to the constant pool. At a minimum items[0] must be an ASCIZ item with the name of the attribute. If the body of the attribute references constant pool items these should be in the item list as well.

 o getAttribute
 public futils.utils.AttributeInfo getAttribute(java.lang.String name)
Return the attribute named 'name' from the class file.

 o getConstantPoolItem
 public futils.utils.ConstantPoolInfo getConstantPoolItem(short index) throws java.lang.Exception
Return a constant pool item from this class. (note does fixup of indexes to facilitate extracting nested or linked items.

 o mapClass
 public void mapClass(java.lang.String oldClass,
                      java.lang.String newClass)
Map occurences of class oldClass to occurrences of class newClass. This method is used to retarget accesses to one class, seamlessly to another. The format for the class name is slash (/) separated so the class util.ClassFile would be represented as util/ClassFile

 o mapPackage
 public void mapPackage(java.lang.String oldPackage,
                        java.lang.String newPackage)
Map occurences of package oldPackage to package newPackage. The format for the package name is slash (/) separated so the package java.util would be represented as java/util

 o deleteMethod
 public void deleteMethod(java.lang.String name,
                          java.lang.String signature)
Delete a named method from this class. This method is used to excise specific methods from the loaded class. The actual method code remains, however the method signature is deleted from the constant pool. If this method is called by a class the exception IncompatibleClassChangeException is generated by the runtime.


All Packages  Class Hierarchy  This Package  Previous  Next  Index