public abstract class AbstractStructure extends Object
Provides common services such as reading, writing and debugging.
Modifier and Type | Field and Description |
---|---|
protected ClassFile |
classFile
Parent class file for this structure.
|
protected boolean |
debug
Flag for debugging while reading and writing class files.
|
static String |
SYSTEM_PROPERTY_DEBUG
Set this JVM System property to true to switch on debugging for
reading and writing class files.
|
Modifier | Constructor and Description |
---|---|
protected |
AbstractStructure()
Constructor.
|
Modifier and Type | Method and Description |
---|---|
protected void |
debug(String message)
Utility method for derived structures.
|
ClassFile |
getClassFile()
Get parent class file.
|
boolean |
getDebug()
Get the debug mode for this structure.
|
protected int |
getLength(Object array)
Utility method for derived structures.
|
protected String |
printAccessFlags(int accessFlags)
Utility method for derived structures.
|
protected abstract String |
printAccessFlagsVerbose(int accessFlags)
Utility method for derived structures.
|
protected String |
printAccessFlagsVerbose(int[] availableAccessFlags,
String[] availableAccessFlagsVerbose,
int accessFlags)
Utility method for derived structures.
|
protected String |
printBytes(int bytes)
Utility method for derived structures.
|
void |
read(DataInput in)
Read this structure from the given DataInput.
|
void |
setClassFile(ClassFile classFile)
Set parent class file.
|
void |
setDebug(boolean debug)
Set the debug mode for this structure.
|
void |
write(DataOutput out)
Write this structure to the given DataOutput.
|
public static final String SYSTEM_PROPERTY_DEBUG
protected ClassFile classFile
protected boolean debug
public ClassFile getClassFile()
public void setClassFile(ClassFile classFile)
Has to be called at least once on a structure.
classFile
- the new parent class filepublic void read(DataInput in) throws InvalidByteCodeException, IOException
Excpects DataInput to be in JVM class file format and just before a structure of this kind. No look ahead parsing since the class file format is deterministic.
in
- the DataInput from which to readInvalidByteCodeException
- if the byte code is invalidIOException
- if an exception occurs with the DataInputpublic void write(DataOutput out) throws InvalidByteCodeException, IOException
The written bytes are in JVM class file format.
out
- the DataOutput to which to writeInvalidByteCodeException
- if the structure is internally inconsistentIOException
- if an exception occurs with the DataOutputpublic boolean getDebug()
public void setDebug(boolean debug)
debug
- the new debug modeprotected int getLength(Object array)
array
- the array for which the length is requestedprotected void debug(String message)
message
- the debug messageprotected String printBytes(int bytes)
bytes
- the int value to print as a hex stringprotected String printAccessFlags(int accessFlags)
accessFlags
- the unsigned short value to print as a hex stringprotected abstract String printAccessFlagsVerbose(int accessFlags)
accessFlags
- the unsigned short value to print as a hex stringprotected String printAccessFlagsVerbose(int[] availableAccessFlags, String[] availableAccessFlagsVerbose, int accessFlags)
availableAccessFlags
- array with the access flags available
for the derived structureavailableAccessFlagsVerbose
- array with verbose description
of the access flags available for the derived structureaccessFlags
- the unsigned short value to print as a hex string