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:
- AttributeInfo, ConstantPoolInfo, MethodInfo, FieldInfo
-
ACC_ABSTRACT
-
-
ACC_FINAL
-
-
ACC_INTERFACE
-
-
ACC_NATIVE
-
-
ACC_PRIVATE
-
-
ACC_PROTECTED
-
-
ACC_PUBLIC
-
-
ACC_STATIC
-
-
ACC_SYNCHRONIZED
-
-
ACC_THREADSAFE
-
-
ACC_TRANSIENT
-
-
debug
-
-
dumpConstants
-
-
ClassFile()
-
-
accessString(short)
-
Returns a string that represents what the access flags
are set for.
-
addAttribute(AttributeInfo)
-
Add a new optional class Attribute.
-
addConstantPoolItem(ConstantPoolInfo)
-
Add a single constant pool item and return its index.
-
addConstantPoolItems(ConstantPoolInfo[])
-
Add some items to the constant pool.
-
deleteMethod(String, String)
-
Delete a named method from this class.
-
display(PrintStream)
-
Write out a text version of this class.
-
getAttribute(String)
-
Return the attribute named 'name' from the class file.
-
getClassName()
-
-
getConstantPoolItem(short)
-
Return a constant pool item from this class.
-
getConstantRef(short)
-
-
mapClass(String, String)
-
Map occurences of class oldClass to occurrences of
class newClass.
-
mapPackage(String, String)
-
Map occurences of package oldPackage to package
newPackage.
-
nextSig(String)
-
Returns the next signature from a string of concatenated signatures.
-
read(InputStream)
-
Read a class from InputStream in.
-
toString()
-
The boring version of display().
-
typeString(String, String)
-
Takes a type signature and a string representing a variable name
and returns a declaration for that variable name.
-
write(OutputStream)
-
Write the class out as a stream of bytes to the output
stream.
ACC_PUBLIC
public static final int ACC_PUBLIC
ACC_PRIVATE
public static final int ACC_PRIVATE
ACC_PROTECTED
public static final int ACC_PROTECTED
ACC_STATIC
public static final int ACC_STATIC
ACC_FINAL
public static final int ACC_FINAL
ACC_SYNCHRONIZED
public static final int ACC_SYNCHRONIZED
ACC_THREADSAFE
public static final int ACC_THREADSAFE
ACC_TRANSIENT
public static final int ACC_TRANSIENT
ACC_NATIVE
public static final int ACC_NATIVE
ACC_INTERFACE
public static final int ACC_INTERFACE
ACC_ABSTRACT
public static final int ACC_ABSTRACT
debug
public boolean debug
dumpConstants
public boolean dumpConstants
ClassFile
public ClassFile()
read
public boolean read(java.io.InputStream in) throws java.io.IOException
- Read a class from InputStream in.
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.
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 "
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[]"
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"
getClassName
public java.lang.String getClassName()
toString
public java.lang.String toString()
- The boring version of display().
- Overrides:
- toString in class java.lang.Object
display
public void display(java.io.PrintStream ps) throws java.lang.Exception
- Write out a text version of this class.
getConstantRef
public futils.utils.ConstantPoolInfo getConstantRef(short index)
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.
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.
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.
getAttribute
public futils.utils.AttributeInfo getAttribute(java.lang.String name)
- Return the attribute named 'name' from the class file.
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.
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
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
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