public abstract class Utility extends Object
Constructor and Description |
---|
Utility() |
Modifier and Type | Method and Description |
---|---|
static String |
accessToString(int accessFlags)
Convert bit field of flags into string such as 'static final'.
|
static String |
accessToString(int accessFlags,
boolean forClass)
Convert bit field of flags into string such as 'static final'.
|
static String |
classOrInterface(int accessFlags) |
static int |
clearBit(int flag,
int i) |
static String |
codeToString(byte[] code,
ConstantPool constantPool,
int index,
int length) |
static String |
codeToString(byte[] code,
ConstantPool constantPool,
int index,
int length,
boolean verbose)
Disassemble a byte array of JVM byte codes starting from code line 'index' and return the disassembled string
representation.
|
static String |
codeToString(ByteSequence bytes,
ConstantPool constantPool) |
static String |
codeToString(ByteSequence bytes,
ConstantPool constantPool,
boolean verbose)
Disassemble a stream of byte codes and return the string representation.
|
static String |
compactClassName(String str)
Shorten long class names, java/lang/String becomes String.
|
static String |
compactClassName(String str,
boolean chopit)
Shorten long class names, java/lang/String becomes java.lang.String, e.g..
|
static String |
compactClassName(String str,
String prefix,
boolean chopit)
Shorten long class name str, i.e., chop off the prefix, if the class name starts with this string
and the flag chopit is true.
|
static String |
convertString(String label)
Escape all occurrences of newline chars '\n', quotes \", etc.
|
static byte[] |
decode(String s,
boolean uncompress)
Decode a string back to a byte array.
|
static String |
encode(byte[] bytes,
boolean compress)
Encode byte array it into Java identifier string, i.e., a string that only contains the following characters: (a, ...
|
static String |
fillup(String str,
int length,
boolean leftJustify,
char fill)
Fillup char with up to length characters with char 'fill' and justify it left or right.
|
static String |
format(int i,
int length,
boolean leftJustify,
char fill)
Return a string for an integer justified left or right and filled up with 'fill' characters if necessary.
|
static String |
getSignature(String type)
Parse Java type such as "char", or "java.lang.String[]" and return the signature in byte code format, e.g.
|
static boolean |
isJavaIdentifierPart(char ch) |
static boolean |
isSet(int flag,
int i) |
static String[] |
methodSignatureArgumentTypes(String signature)
Converts argument list portion of method signature to string with all class names compacted.
|
static String[] |
methodSignatureArgumentTypes(String signature,
boolean chopit)
Converts argument list portion of method signature to string.
|
static String |
methodSignatureReturnType(String signature)
Converts return type portion of method signature to string with all class names compacted.
|
static String |
methodSignatureReturnType(String signature,
boolean chopit)
Converts return type portion of method signature to string.
|
static String |
methodSignatureToString(String signature,
String name,
String access)
Converts method signature to string with all class names compacted.
|
static String |
methodSignatureToString(String signature,
String name,
String access,
boolean chopit)
Converts method signature to string.
|
static String |
methodSignatureToString(String signature,
String name,
String access,
boolean chopit,
LocalVariableTable vars)
This method converts a method signature string into a Java type declaration like 'void main(String[])' and throws a
'ClassFormatException' when the parsed type is invalid.
|
static String |
methodTypeToSignature(String ret,
String[] argv)
Converts string containing the method return and argument types to a byte code method signature.
|
static String |
packageToPath(String name)
Converts '.'s to '/'s.
|
static String |
pathToPackage(String str)
Converts a path to a package name.
|
static String |
printArray(Object[] obj) |
static String |
printArray(Object[] obj,
boolean braces) |
static String |
printArray(Object[] obj,
boolean braces,
boolean quote) |
static void |
printArray(PrintStream out,
Object[] obj) |
static void |
printArray(PrintWriter out,
Object[] obj) |
static String |
replace(String str,
String old,
String new_)
Replace all occurrences of old in str with new.
|
static short |
searchOpcode(String name)
Map opcode names to opcode numbers.
|
static int |
setBit(int flag,
int i) |
static String |
signatureToString(String signature)
Converts a signature to a string with all class names compacted.
|
static String |
signatureToString(String signature,
boolean chopit)
Converts a signature to a string.
|
static String |
toHexString(byte[] bytes)
Convert bytes into hexadecimal string
|
static byte |
typeOfMethodSignature(String signature)
Return type of method signature as a byte value as defined in Constants
|
static byte |
typeOfSignature(String signature)
Return type of signature as a byte value as defined in Constants
|
static String |
typeSignatureToString(String signature,
boolean chopit)
This method converts a type signature string into a Java type declaration such as 'String[]' and throws a
'ClassFormatException' when the parsed type is invalid.
|
public static String accessToString(int accessFlags)
accessFlags
- Access flagspublic static String accessToString(int accessFlags, boolean forClass)
accessFlags
- Access flagsforClass
- access flags are for class qualifiers ?public static String classOrInterface(int accessFlags)
accessFlags
- the class flagspublic static int clearBit(int flag, int i)
public static String codeToString(byte[] code, ConstantPool constantPool, int index, int length)
public static String codeToString(byte[] code, ConstantPool constantPool, int index, int length, boolean verbose)
code
- byte code arrayconstantPool
- Array of constantsindex
- offset in 'code' array (number of opcodes, not bytes!)length
- number of opcodes to decompile, -1 for allverbose
- be verbose, e.g. print constant pool indexpublic static String codeToString(ByteSequence bytes, ConstantPool constantPool) throws IOException
IOException
public static String codeToString(ByteSequence bytes, ConstantPool constantPool, boolean verbose) throws IOException
bytes
- stream of bytesconstantPool
- Array of constantsverbose
- be verbose, e.g. print constant pool indexIOException
- if a failure from reading from the bytes argument occurspublic static String compactClassName(String str)
str
- The long class namepublic static String compactClassName(String str, boolean chopit)
str
- The long class namechopit
- flag that determines whether chopping is executed or notpublic static String compactClassName(String str, String prefix, boolean chopit)
str
- The long class nameprefix
- The prefix the get rid offchopit
- flag that determines whether chopping is executed or notpublic static String convertString(String label)
public static byte[] decode(String s, boolean uncompress) throws IOException
s
- the string to convertuncompress
- use gzip to uncompress the stream of bytesIOException
- if there's a gzip exceptionpublic static String encode(byte[] bytes, boolean compress) throws IOException
This operation inflates the original byte array by roughly 40-50%
bytes
- the byte array to convertcompress
- use gzip to minimize stringIOException
- if there's a gzip exceptionpublic static String fillup(String str, int length, boolean leftJustify, char fill)
str
- string to formatlength
- length of desired stringleftJustify
- format left or rightfill
- fill characterpublic static String format(int i, int length, boolean leftJustify, char fill)
i
- integer to formatlength
- length of desired stringleftJustify
- format left or rightfill
- fill characterpublic static String getSignature(String type)
type
- Java typepublic static boolean isJavaIdentifierPart(char ch)
ch
- the character to test if it's part of an identifierpublic static boolean isSet(int flag, int i)
public static String[] methodSignatureArgumentTypes(String signature) throws ClassFormatException
signature
- Method signatureClassFormatException
- if a class is malformed or cannot be interpreted as a class filepublic static String[] methodSignatureArgumentTypes(String signature, boolean chopit) throws ClassFormatException
signature
- Method signaturechopit
- flag that determines whether chopping is executed or notClassFormatException
- if a class is malformed or cannot be interpreted as a class filepublic static String methodSignatureReturnType(String signature) throws ClassFormatException
signature
- Method signatureClassFormatException
- if a class is malformed or cannot be interpreted as a class filepublic static String methodSignatureReturnType(String signature, boolean chopit) throws ClassFormatException
signature
- Method signaturechopit
- flag that determines whether chopping is executed or notClassFormatException
- if a class is malformed or cannot be interpreted as a class filepublic static String methodSignatureToString(String signature, String name, String access)
signature
- to convertname
- of methodaccess
- flags of methodpublic static String methodSignatureToString(String signature, String name, String access, boolean chopit)
signature
- to convertname
- of methodaccess
- flags of methodchopit
- flag that determines whether chopping is executed or notpublic static String methodSignatureToString(String signature, String name, String access, boolean chopit, LocalVariableTable vars) throws ClassFormatException
signature
- Method signaturename
- Method nameaccess
- Method access rightschopit
- flag that determines whether chopping is executed or notvars
- the LocalVariableTable for the methodClassFormatException
- if a class is malformed or cannot be interpreted as a class filepublic static String methodTypeToSignature(String ret, String[] argv) throws ClassFormatException
ret
- Return type of methodargv
- Types of method argumentsClassFormatException
- if the signature is for Voidpublic static String packageToPath(String name)
name
- Sourcepublic static String pathToPackage(String str)
str
- the source path.public static void printArray(PrintStream out, Object[] obj)
public static void printArray(PrintWriter out, Object[] obj)
public static String replace(String str, String old, String new_)
str
- String to permuteold
- String to be replacednew_
- Replacement stringpublic static short searchOpcode(String name)
public static int setBit(int flag, int i)
public static String signatureToString(String signature)
signature
- signature to convertpublic static String signatureToString(String signature, boolean chopit)
signature
- signature to convertchopit
- flag that determines whether chopping is executed or notpublic static String toHexString(byte[] bytes)
bytes
- an array of bytes to convert to hexadecimalpublic static byte typeOfMethodSignature(String signature) throws ClassFormatException
signature
- in format described aboveClassFormatException
- if signature is not a method signatureConst
public static byte typeOfSignature(String signature) throws ClassFormatException
signature
- in format described aboveClassFormatException
- if signature isn't a known typeConst
public static String typeSignatureToString(String signature, boolean chopit) throws ClassFormatException
signature
- type signaturechopit
- flag that determines whether chopping is executed or notClassFormatException
- if a class is malformed or cannot be interpreted as a class fileCopyright © 2004–2024 The Apache Software Foundation. All rights reserved.