|
Java API by Zvi Har’El |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcf.ClassFile
public class ClassFile
An instance of class ClassFile is an in-core representation of
a Java class file.
| Nested Class Summary | |
|---|---|
protected static class |
ClassFile.ByteArray
An instance of the inner class ByteArray is an
immutable wrapper to a byte[] object. |
| Field Summary | |
|---|---|
(package private) short |
access
Class access modifiers. |
(package private) Vector |
attributes
Attributes of this class. |
(package private) Vector |
cP
Constant pool. |
(package private) short |
cPCode
UTF8 constant for “Code”. |
(package private) Hashtable |
cPHash
Constant pool hash table. |
(package private) Vector |
fields
Fields declared by this class. |
(package private) Vector |
interfaces
Superinterfaces of this class. |
(package private) short |
major
Major version number of this class file. |
(package private) Vector |
methods
Methods declared by this class. |
(package private) short |
minor
Minor version number of this class file. |
(package private) short |
superClass
The direct superclass of this class. |
(package private) short |
thisClass
The class defined by this class file. |
| Constructor Summary | |
|---|---|
ClassFile()
Constructs an empty ClassFile object. |
|
ClassFile(DataInputStream in)
Constructs a ClassFile object by reading an input
stream. |
|
| Method Summary | |
|---|---|
void |
addInterface(String name)
Adds a name to the list of interfaces implemented by this class. |
private short |
cp(byte[] b)
Inserts a constant to the pool. |
(package private) short |
cp(byte tag,
double c)
Inserts a DOUBLE constant. |
(package private) short |
cp(byte tag,
float c)
Inserts a FLOAT constant. |
(package private) short |
cp(byte tag,
int c)
Inserts an INTEGER constant. |
(package private) short |
cp(byte tag,
long c)
Inserts a LONG constant. |
private short |
cp(byte tag,
short i)
Inserts a constant. |
private short |
cp(byte tag,
short i,
short j)
Inserts a constant. |
(package private) short |
cp(byte tag,
short i,
String name,
String desc)
Inserts a FIELDREF, METHODREF or
INTERFACEMETHODREF constant. |
(package private) short |
cp(byte tag,
String s)
Inserts a UTF8, CLASS or
STRING constant. |
(package private) short |
cp(byte tag,
String name,
String desc)
Inserts a NAMEANDTYPE constant. |
(package private) short |
cp(byte tag,
String s,
String name,
String desc)
Inserts a FIELDREF, METHODREF or
INTERFACEMETHODREF constant. |
(package private) static String |
desc(Class type)
Returns a descriptor of a field. |
(package private) static String |
desc(Class[] param,
Class type)
Returns a descriptor of a method. |
static InputStream |
findClassInPath(String name)
Finds a class file in the user class path. |
(package private) short |
findUTF8(String s)
Finds a UTF8 constant in the pool. |
byte[] |
getBytes()
Writes the ClassFile object on a byte array. |
static ClassFile |
getClassFile(String name)
Gets a ClassFile object for a named class by reading a class
file from the user class path. |
(package private) Object |
readAttribute(DataInputStream in)
Reads an attribute table from the input stream. |
(package private) void |
renameClass(short i,
String name)
Renames a class. |
void |
setName(String name)
Sets the name of this class. |
void |
setSuper(String name)
Sets the name of the direct superclass of this class. |
void |
strip()
Strips attributes. |
(package private) static byte[] |
toUTF8(String s)
Computes the UTF-8 encoding of a string. |
void |
write(DataOutputStream out)
Writes the ClassFile object on an output stream. |
void |
write(String s)
Writes the ClassFile object on a file. |
(package private) static void |
writeAttribute(DataOutputStream out,
byte[] b)
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
final Vector cP
ClassFile.ByteArray object.
final Hashtable cPHash
short cPCode
UTF8 constant for “Code”.
short minor
short major
short access
modifiers.
short thisClass
CLASS constant.
short superClass
CLASS constant.
final Vector interfaces
Short
object wrapping an index to a CLASS constant.
final Vector fields
MemberInfo
object.
final Vector methods
MemberInfo
object.
final Vector attributes
“SourceFile”. Each entry is a byte array.
| Constructor Detail |
|---|
ClassFile()
ClassFile object.
public ClassFile(DataInputStream in)
throws IOException
ClassFile object by reading an input
stream.
in - the input stream
ClassFormatError - if input cannot be interpreted as a class file
IOException - if input error occurs| Method Detail |
|---|
public static ClassFile getClassFile(String name)
throws IOException,
ClassNotFoundException
ClassFile object for a named class by reading a class
file from the user class path.
name - the class name
IOException - if input error occurs
ClassFormatError - if input cannot be interpreted as a class file
ClassNotFoundException - if class file is not found
public static final InputStream findClassInPath(String name)
throws ClassNotFoundException
name - the class name
ClassNotFoundException - if class file is not found
public final void write(DataOutputStream out)
throws IOException
ClassFile object on an output stream.
out - the output stream
IOException - if output error occurs
public final void write(String s)
throws IOException
ClassFile object on a file.
s - a file name
IOException - if output error occurs
public final byte[] getBytes()
throws IOException
ClassFile object on a byte array.
IOException - if output error occurspublic final void strip()
private final short cp(byte[] b)
b - a byte array
private final short cp(byte tag,
short i)
tag - a constant pool tagi - an index to constant pool
private final short cp(byte tag,
short i,
short j)
tag - a constant pool tagi - an index to constant poolj - an index to constant pool
final short cp(byte tag,
String s)
UTF8, CLASS or
STRING constant. In the latter cases, an intermediate
UTF8 constant is created.
tag - a constant pool tags - a String value
final short cp(byte tag,
String name,
String desc)
NAMEANDTYPE constant. Two intermediate
UTF8 constants are created.
tag - a constant pool tagname - a member namedesc - a member descriptor
final short cp(byte tag,
String s,
String name,
String desc)
FIELDREF, METHODREF or
INTERFACEMETHODREF constant. Two intermediate
CLASS and NAMEANDTYPE constants are
created.
tag - a constant pool tags - a class name in internal formname - a member namedesc - a member descriptor
final short cp(byte tag,
short i,
String name,
String desc)
FIELDREF, METHODREF or
INTERFACEMETHODREF constant. An intermediate
NAMEANDTYPE constant is created.
tag - a constant pool tagi - an index to a CLASS constantname - a member namedesc - a member descriptor
final short cp(byte tag,
int c)
INTEGER constant. Also called internally to
insert a four-byte constant which contains a float
value.
tag - a constant pool tagc - an int value
final short cp(byte tag,
float c)
FLOAT constant.
tag - a constant pool tagc - a float value
final short cp(byte tag,
long c)
LONG constant. Also called internally to
insert an eight-byte constant which contains a double
value. The next pool entry is marked invalid.
tag - a constant pool tagc - a long value
final short cp(byte tag,
double c)
DOUBLE constant.
tag - a constant pool tagc - a double value
static final byte[] toUTF8(String s)
s - a String value
DataOutput.writeUTF(java.lang.String),
RFC2279final short findUTF8(String s)
UTF8 constant in the pool.
s - a String value
public final void setName(String name)
name - a class name.public final void setSuper(String name)
name - a class name.
final void renameClass(short i,
String name)
CLASS constant is removed from the
pool and a new CLASS constant is inserted in the same
place.
i - an index to a CLASS constantname - a class name in internal form.public final void addInterface(String name)
name - a class name.
final Object readAttribute(DataInputStream in)
throws IOException
“Code” attributes are transformed into CodeAttribute objects.
in - the input stream
IOException - if an input error occurs.
static final void writeAttribute(DataOutputStream out,
byte[] b)
throws IOException
IOExceptionstatic final String desc(Class type)
type - the field type
static final String desc(Class[] param,
Class type)
null or an empty Class array are
acceptable as the parameter types.
param - the parameter typestype - the return type
|
Java API by Zvi Har’El |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||