Top Description Inners Fields Constructors Methods
org.apache.bcel.classfile

public abstract Class Utility

extends Object
Class Inheritance
Imports
java.io.ByteArrayInputStream, .ByteArrayOutputStream, .CharArrayReader, .CharArrayWriter, .FilterReader, .FilterWriter, .IOException, .PrintStream, .PrintWriter, .Reader, .Writer, java.util.ArrayList, .Arrays, .List, .Locale, java.util.zip.GZIPInputStream, .GZIPOutputStream, org.apache.bcel.Const, org.apache.bcel.util.ByteSequence, org.apache.commons.lang3.ArrayUtils

Utility functions that do not really belong to any class in particular.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
Utility.JavaReader

Decode characters into bytes.

private static class
Utility.JavaWriter

Encode bytes into valid Java identifier characters.

Field Summary

Modifier and TypeField and Description
private static final int[]
private static final ThreadLocal<Integer>
private static final char
private static final int
private static final int[]
private static boolean

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static String

Returns:

String representation of flags
accessToString
(final int
Access flags
accessFlags
)

Convert bit field of flags into string such as 'static final'.

public static String

Returns:

String representation of flags
accessToString
(final int
Access flags
accessFlags
,
final boolean
access flags are for class qualifiers ?
forClass
)

Convert bit field of flags into string such as 'static final'.

private static short
byteToShort(final byte b)

Convert (signed) byte to (unsigned) short value, i.e., all negative values become positive.

public static String

Returns:

"class" or "interface", depending on the ACC_INTERFACE flag
classOrInterface
(final int
the class flags
accessFlags
)

public static int

Returns:

'flag' with bit 'i' set to 0
clearBit
(final int flag, final int i)

public static String
codeToString(final byte[] code, final ConstantPool constantPool, final int index, final int length)

public static String

Returns:

String representation of byte codes
codeToString
(final byte[]
byte code array
code
,
final ConstantPool
Array of constants
constantPool
,
final int
offset in 'code' array (number of opcodes, not bytes!)
index
,
final int
number of opcodes to decompile, -1 for all
length
,
final boolean
be verbose, e.g. print constant pool index
verbose
)

Disassemble a byte array of JVM byte codes starting from code line 'index' and return the disassembled string representation.

public static String
codeToString(final ByteSequence bytes, final ConstantPool constantPool)

public static String

Returns:

String representation of byte code
codeToString
(final ByteSequence
stream of bytes
bytes
,
final ConstantPool
Array of constants
constantPool
,
final boolean
be verbose, e.g. print constant pool index
verbose
)

Disassemble a stream of byte codes and return the string representation.

public static String

Returns:

Compacted class name
compactClassName
(final String
The long class name
str
)

Shorten long class names, java/lang/String becomes String.

public static String

Returns:

Compacted class name
compactClassName
(final String
The long class name
str
,
final boolean
flag that determines whether chopping is executed or not
chopit
)

Shorten long class names, java/lang/String becomes java.lang.String, e.g..

public static String

Returns:

Compacted class name
compactClassName
(String
The long class name
str
,
final String
The prefix the get rid off
prefix
,
final boolean
flag that determines whether chopping is executed or not
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.

public static String
convertString(final String label)

Escape all occurrences of newline chars '\n', quotes \", etc.

private static int
countBrackets(final String brackets)

public static byte[]
decode(final String
the string to convert
s
,
final boolean
use gzip to uncompress the stream of bytes
uncompress
)

Decode a string back to a byte array.

public static String
encode(byte[]
the byte array to convert
bytes
,
final boolean
use gzip to minimize string
compress
)

Encode byte array it into Java identifier string, i.e., a string that only contains the following characters: (a, ...

public static String

Returns:

formatted string
fillup
(final String
string to format
str
,
final int
length of desired string
length
,
final boolean
format left or right
leftJustify
,
final char
fill character
fill
)

Fillup char with up to length characters with char 'fill' and justify it left or right.

public static String

Returns:

formatted int
format
(final int
integer to format
i
,
final int
length of desired string
length
,
final boolean
format left or right
leftJustify
,
final char
fill character
fill
)

Return a string for an integer justified left or right and filled up with 'fill' characters if necessary.

public static String

Returns:

byte code signature
getSignature
(String
Java type
type
)

Parse Java type such as "char", or "java.lang.String[]" and return the signature in byte code format, e.g. "C" or "[Ljava/lang/String;" respectively.

public static boolean

Returns:

true, if character is one of (a, ... z, A, ... Z, 0, ... 9, _)
isJavaIdentifierPart
(final char
the character to test if it's part of an identifier
ch
)

public static boolean

Returns:

true, if bit 'i' in 'flag' is set
isSet
(final int flag, final int i)

public static String[]

Returns:

String Array of argument types
methodSignatureArgumentTypes
(final String
Method signature
signature
)

Converts argument list portion of method signature to string with all class names compacted.

public static String[]

Returns:

String Array of argument types
methodSignatureArgumentTypes
(final String
Method signature
signature
,
final boolean
flag that determines whether chopping is executed or not
chopit
)

Converts argument list portion of method signature to string.

public static String

Returns:

String representation of method return type
methodSignatureReturnType
(final String
Method signature
signature
)

Converts return type portion of method signature to string with all class names compacted.

public static String

Returns:

String representation of method return type
methodSignatureReturnType
(final String
Method signature
signature
,
final boolean
flag that determines whether chopping is executed or not
chopit
)

Converts return type portion of method signature to string.

public static String

Returns:

Human readable signature
methodSignatureToString
(final String
to convert
signature
,
final String
of method
name
,
final String
flags of method
access
)

Converts method signature to string with all class names compacted.

public static String

Returns:

Human readable signature
methodSignatureToString
(final String
to convert
signature
,
final String
of method
name
,
final String
flags of method
access
,
final boolean
flag that determines whether chopping is executed or not
chopit
)

Converts method signature to string.

public static String

Returns:

Java type declaration
methodSignatureToString
(final String
Method signature
signature
,
final String
Method name
name
,
final String
Method access rights
access
,
final boolean
flag that determines whether chopping is executed or not
chopit
,
final LocalVariableTable
the LocalVariableTable for the method
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.

public static String

Returns:

Byte code representation of method signature
methodTypeToSignature
(final String
Return type of method
ret
,
final String[]
Types of method arguments
argv
)

Converts string containing the method return and argument types to a byte code method signature.

public static String

Returns:

converted value
packageToPath
(final String
Source
name
)

Converts '.'s to '/'s.

public static String

Returns:

a package name.
pathToPackage
(final String
the source path.
str
)

Converts a path to a package name.

private static int
pow2(final int n)

public static String
printArray(final Object[] obj)

public static String
printArray(final Object[] obj, final boolean braces)

public static String
printArray(final Object[] obj, final boolean braces, final boolean quote)

public static void
printArray(final PrintStream out, final Object[] obj)

public static void
printArray(final PrintWriter out, final Object[] obj)

public static String

Returns:

new String object
replace
(String
String to permute
str
,
final String
String to be replaced
old
,
final String
Replacement string
new_
)

Replace all occurrences of old in str with new.

public static short
searchOpcode(String name)

Map opcode names to opcode numbers.

public static int

Returns:

'flag' with bit 'i' set to 1
setBit
(final int flag, final int i)

public static String

Returns:

String containg human readable signature
signatureToString
(final String
signature to convert
signature
)

Converts a signature to a string with all class names compacted.

public static String

Returns:

String containg human readable signature
signatureToString
(final String
signature to convert
signature
,
final boolean
flag that determines whether chopping is executed or not
chopit
)

Converts a signature to a string.

public static String

Returns:

bytes as hexadecimal string, e.g. 00 fa 12 ...
toHexString
(final byte[]
an array of bytes to convert to hexadecimal
bytes
)

Convert bytes into hexadecimal string

public static byte

Returns:

type of method signature
typeOfMethodSignature
(final String
in format described above
signature
)

Return type of method signature as a byte value as defined in Constants

public static byte

Returns:

type of signature
typeOfSignature
(final String
in format described above
signature
)

Return type of signature as a byte value as defined in Constants

private static String

Returns:

String containg human readable signature
typeParamTypesToString
(final String
signature to convert
signature
,
final boolean
flag that determines whether chopping is executed or not
chopit
)

Converts a type parameter list signature to a string.

private static String

Returns:

String containg human readable signature
typeParamTypeToString
(final String
signature to convert
signature
,
final boolean
flag that determines whether chopping is executed or not
chopit
)

Converts a type parameter signature to a string.

private static String

Returns:

String containg human readable signature
typeSignaturesToString
(final String
signature to convert
signature
,
final boolean
flag that determines whether chopping is executed or not
chopit
,
final char
character indicating the end of the list
term
)

Converts a list of type signatures to a string.

public static String

Returns:

string containing human readable type signature
typeSignatureToString
(final String
type signature
signature
,
final boolean
flag that determines whether chopping is executed or not
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.

private static int
private static void
wrap(final ThreadLocal<Integer> tl, final int value)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait