|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object | +--com.objectwave.classFile.ClassFile
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() .
AttributeInfo,
ConstantPoolInfo,
MethodInfo,
FieldInfo| Nested Class Summary | |
static class |
ClassFile.Test
|
| Field Summary | |
boolean |
debug
Description of the Field |
boolean |
dumpConstants
Description of the Field |
static int |
MOD_ABSTRACT
Description of the Field |
static int |
MOD_FINAL
Description of the Field |
static int |
MOD_INTERFACE
Description of the Field |
static int |
MOD_NATIVE
Description of the Field |
static int |
MOD_PRIVATE
Description of the Field |
static int |
MOD_PROTECTED
Description of the Field |
static int |
MOD_PUBLIC
Description of the Field |
static int |
MOD_STATIC
Description of the Field |
static int |
MOD_SYNCHRONIZED
Description of the Field |
static int |
MOD_THREADSAFE
Description of the Field |
static int |
MOD_TRANSIENT
Description of the Field |
| Constructor Summary | |
ClassFile()
|
|
| Method Summary | |
static java.lang.String |
accessString(short flags)
Returns a string that represents what the access flags are set for. |
void |
addAttribute(AttributeInfo newAttribute)
Add a new optional class Attribute. |
void |
addAttribute(java.lang.String name,
byte[] newData)
We have to add an item and then get the item so we get the correct ConstantPoolInfo instance. |
short |
addConstantPoolItem(ConstantPoolInfo item)
Add a single constant pool item and return its index. |
void |
addConstantPoolItems(ConstantPoolInfo[] items)
Add some items to the constant pool. |
java.util.Hashtable |
allCalledMethods()
|
boolean |
checkMagic(java.io.DataInputStream di)
|
void |
deleteMethod(java.lang.String name,
java.lang.String signature)
Delete a named method from this class. |
void |
display(java.io.PrintStream ps)
Write out a text version of this class. |
AttributeInfo |
getAttribute(java.lang.String name)
Return the attribute named 'name' from the class file. |
protected static java.io.InputStream |
getByteCodeStream(java.lang.String path,
java.lang.String fName)
|
java.lang.String[] |
getClassDependencies()
|
java.lang.String |
getClassName()
|
ConstantPoolInfo |
getConstantPoolItem(short index)
Return a constant pool item from this class. |
ConstantPoolInfo |
getConstantRef(short index)
Gets the ConstantRef attribute of the ClassFile object |
static ClassFile |
getInstance(java.lang.String classFilePath,
java.lang.String className)
Create a new instance after locating the bytes. |
static ClassFile |
getInstanceWork(java.lang.String pathEntry,
java.lang.String className)
Requires properly formatted parameters. |
java.util.Vector |
getMethodsCalling(java.lang.String methodName,
java.lang.String[] otherClassNames)
|
java.lang.String |
getPackageName()
|
java.lang.String |
getSourceLocation()
The source location is the file system resource (file or from a jar) that should enable one to figure out the source of the bytes codes. |
AttributeInfo[] |
identifyAttributes(java.io.DataInputStream di,
ConstantPoolInfo[] constPool)
|
boolean |
identifyClassParts(java.io.DataInputStream di,
ConstantPoolInfo[] constPool)
|
FieldInfo[] |
identifyFields(java.io.DataInputStream di,
ConstantPoolInfo[] constPool)
|
ConstantPoolInfo[] |
identifyInterfaces(java.io.DataInputStream di,
ConstantPoolInfo[] constPool)
|
MethodInfo[] |
identifyMethods(java.io.DataInputStream di,
ConstantPoolInfo[] constPool)
|
protected void |
insertMethod(java.io.InputStream in)
|
protected boolean |
isPrimitiveConstant(ConstantPoolInfo item)
|
void |
mapClass(java.lang.String oldClass,
java.lang.String newClass)
Map occurences of class oldClass to occurrences of class newClass . |
void |
mapPackage(java.lang.String oldPackage,
java.lang.String newPackage)
Map occurences of package oldPackage to package newPackage . |
static java.lang.String |
nextSig(java.lang.String sig)
Returns the next signature from a string of concatenated signatures. |
boolean |
read(java.io.InputStream in)
Take an InputStream and read in what is believed to be a class file. |
ConstantPoolInfo[] |
readConstantPoolInfo(java.io.DataInputStream di)
|
void |
readVersion(java.io.DataInputStream di)
|
ConstantPoolInfo |
recursiveAdd(ConstantPoolInfo cpi)
Use recursion to ensure that ConstantPoolInfo dependecies are met. |
void |
setSourceLocation(java.lang.String str)
The source location is the file system resource (file or from a jar) that should enable one to figure out the source of the bytes codes. |
java.lang.String |
toString()
|
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. |
void |
updatePointers(ConstantPoolInfo[] constPool)
When we read in the class file, we read the 'index' of the constant pool. |
void |
write(java.io.OutputStream out)
Write the class out as a stream of bytes to the output stream. |
protected void |
writeMethod(java.lang.String methodName,
java.io.OutputStream out)
|
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
public static final int MOD_PUBLIC
public static final int MOD_PRIVATE
public static final int MOD_PROTECTED
public static final int MOD_STATIC
public static final int MOD_FINAL
public static final int MOD_SYNCHRONIZED
public static final int MOD_THREADSAFE
public static final int MOD_TRANSIENT
public static final int MOD_NATIVE
public static final int MOD_INTERFACE
public static final int MOD_ABSTRACT
public boolean debug
public boolean dumpConstants
| Constructor Detail |
public ClassFile()
| Method Detail |
public static ClassFile getInstance(java.lang.String classFilePath,
java.lang.String className)
throws java.io.InvalidClassException
classFilePath - A path to search for the provided className.className - Description of Parameter
java.io.InvalidClassException - Description of Exception
public static ClassFile getInstanceWork(java.lang.String pathEntry,
java.lang.String className)
className - A file name more than a class name. Like
'com/objectwave/classFile/ClassFile.class'.pathEntry - An entry in a class path. Like '/home/dhoag/classes'.
protected static java.io.InputStream getByteCodeStream(java.lang.String path,
java.lang.String fName)
path - The entry in the classpath to searchfName - The file for which this class is searching
public static java.lang.String accessString(short flags)
flags - Description of Parameter
public static java.lang.String nextSig(java.lang.String sig)
sig - Description of Parameter
public static java.lang.String typeString(java.lang.String typeString,
java.lang.String varName)
typeString - Description of ParametervarName - Description of Parameter
public void setSourceLocation(java.lang.String str)
str - The new SourceLocation valuepublic java.lang.String getPackageName()
public java.util.Vector getMethodsCalling(java.lang.String methodName,
java.lang.String[] otherClassNames)
methodName - otherClassNames - String [] of classes to substitute in the className
arg.
public AttributeInfo getAttribute(java.lang.String name)
name - Description of Parameter
public java.lang.String[] getClassDependencies()
throws java.lang.Exception
java.lang.Exception - Description of Exceptionpublic java.lang.String getClassName()
public ConstantPoolInfo getConstantPoolItem(short index)
throws java.lang.Exception
index - Description of Parameter
java.lang.Exception - Description of Exceptionpublic ConstantPoolInfo getConstantRef(short index)
index - Description of Parameter
protected boolean isPrimitiveConstant(ConstantPoolInfo item)
item - Description of Parameter
public java.lang.String getSourceLocation()
public void addAttribute(AttributeInfo newAttribute)
newAttribute - The feature to be added to the Attribute attribute
public void addAttribute(java.lang.String name,
byte[] newData)
throws java.io.IOException,
java.lang.Exception
name - The feature to be added to the Attribute attributenewData - The feature to be added to the Attribute attribute
java.io.IOException - Description of Exception
java.lang.Exception - Description of Exception
public ConstantPoolInfo recursiveAdd(ConstantPoolInfo cpi)
throws java.lang.Exception
cpi - Description of Parameter
java.lang.Exception - Description of Exception
public short addConstantPoolItem(ConstantPoolInfo item)
throws java.lang.Exception
item - The feature to be added to the ConstantPoolItem attribute
java.lang.Exception - Description of Exceptionpublic void addConstantPoolItems(ConstantPoolInfo[] items)
items - The feature to be added to the ConstantPoolItems attribute
public boolean checkMagic(java.io.DataInputStream di)
throws java.io.IOException
di - Description of Parameter
java.io.IOException - Description of Exception
public void deleteMethod(java.lang.String name,
java.lang.String signature)
name - Description of Parametersignature - Description of Parameterpublic java.util.Hashtable allCalledMethods()
public void display(java.io.PrintStream ps)
throws java.lang.Exception
ps - Description of Parameter
java.lang.Exception - Description of Exception
public AttributeInfo[] identifyAttributes(java.io.DataInputStream di,
ConstantPoolInfo[] constPool)
throws java.io.IOException
di - Description of ParameterconstPool - Description of Parameter
java.io.IOException - Description of Exception
public boolean identifyClassParts(java.io.DataInputStream di,
ConstantPoolInfo[] constPool)
throws java.io.IOException
di - Description of ParameterconstPool - Description of Parameter
java.io.IOException - Description of Exception
public FieldInfo[] identifyFields(java.io.DataInputStream di,
ConstantPoolInfo[] constPool)
throws java.io.IOException
di - Description of ParameterconstPool - Description of Parameter
java.io.IOException - Description of Exception
public ConstantPoolInfo[] identifyInterfaces(java.io.DataInputStream di,
ConstantPoolInfo[] constPool)
throws java.io.IOException
di - Description of ParameterconstPool - Description of Parameter
java.io.IOException - Description of Exception
public MethodInfo[] identifyMethods(java.io.DataInputStream di,
ConstantPoolInfo[] constPool)
throws java.io.IOException
di - Description of ParameterconstPool - Description of Parameter
java.io.IOException - Description of Exception
public void mapClass(java.lang.String oldClass,
java.lang.String newClass)
oldClass - Description of ParameternewClass - Description of Parameter
public void mapPackage(java.lang.String oldPackage,
java.lang.String newPackage)
oldPackage - Description of ParameternewPackage - Description of Parameter
public boolean read(java.io.InputStream in)
throws java.io.IOException
in - Description of Parameter
java.io.IOException - Description of Exception
public ConstantPoolInfo[] readConstantPoolInfo(java.io.DataInputStream di)
throws java.io.IOException
di - Description of Parameter
java.io.IOException - Description of Exception
public void readVersion(java.io.DataInputStream di)
throws java.io.IOException
di - Description of Parameter
java.io.IOException - Description of Exceptionpublic java.lang.String toString()
toString in class java.lang.Objectpublic void updatePointers(ConstantPoolInfo[] constPool)
constPool - Description of Parameter
public void write(java.io.OutputStream out)
throws java.io.IOException,
java.lang.Exception
out - Description of Parameter
java.io.IOException - Description of Exception
java.lang.Exception - Description of Exception
protected void insertMethod(java.io.InputStream in)
throws java.io.IOException,
java.lang.Exception
in - Description of Parameter
java.io.IOException - Description of Exception
java.lang.Exception - Description of Exception
protected void writeMethod(java.lang.String methodName,
java.io.OutputStream out)
throws java.io.IOException,
java.lang.Exception
methodName - Description of Parameterout - Description of Parameter
java.io.IOException - Description of Exception
java.lang.Exception - Description of Exception
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||