Apache Tomcat 7.0.28

org.apache.tomcat.util.bcel.classfile
Class Utility

java.lang.Object
  extended by org.apache.tomcat.util.bcel.classfile.Utility

public abstract class Utility
extends Object

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

Version:
$Id: Utility.java 1181133 2011-10-10 18:49:14Z markt $
Author:
M. Dahm

Constructor Summary
Utility()
           
 
Method Summary
static String accessToString(int access_flags)
          Convert bit field of flags into string such as `static final'.
static String accessToString(int access_flags, boolean for_class)
          Convert bit field of flags into string such as `static final'.
static String classOrInterface(int access_flags)
           
static String codeToString(byte[] code, ConstantPool constant_pool, 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 constant_pool, 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 occurences of newline chars '\n', quotes \", etc.
static String fillup(String str, int length, boolean left_justify, char fill)
          Fillup char with up to length characters with char `fill' and justify it left or right.
static String methodSignatureToString(String signature, String name, String access, boolean chopit, LocalVariableTable vars)
          A returntype signature represents the return value from a method.
static String replace(String str, String old, String new_)
          Replace all occurrences of old in str with new.
static String signatureToString(String signature)
          Converts signature to string with all class names compacted.
static String signatureToString(String signature, boolean chopit)
          The field signature represents the value of an argument to a function or the value of a variable.
static String toHexString(byte[] bytes)
          Convert bytes into hexadecimal string
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Utility

public Utility()
Method Detail

accessToString

public static final String accessToString(int access_flags)
Convert bit field of flags into string such as `static final'.

Parameters:
access_flags - Access flags
Returns:
String representation of flags

accessToString

public static final String accessToString(int access_flags,
                                          boolean for_class)
Convert bit field of flags into string such as `static final'. Special case: Classes compiled with new compilers and with the `ACC_SUPER' flag would be said to be "synchronized". This is because SUN used the same value for the flags `ACC_SUPER' and `ACC_SYNCHRONIZED'.

Parameters:
access_flags - Access flags
for_class - access flags are for class qualifiers ?
Returns:
String representation of flags

classOrInterface

public static final String classOrInterface(int access_flags)
Parameters:
access_flags - the class flags
Returns:
"class" or "interface", depending on the ACC_INTERFACE flag

codeToString

public static final String codeToString(byte[] code,
                                        ConstantPool constant_pool,
                                        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. Decode only `num' opcodes (including their operands), use -1 if you want to decompile everything.

Parameters:
code - byte code array
constant_pool - Array of constants
index - offset in `code' array (number of opcodes, not bytes!)
length - number of opcodes to decompile, -1 for all
verbose - be verbose, e.g. print constant pool index
Returns:
String representation of byte codes

codeToString

public static final String codeToString(ByteSequence bytes,
                                        ConstantPool constant_pool,
                                        boolean verbose)
                                 throws IOException
Disassemble a stream of byte codes and return the string representation.

Parameters:
bytes - stream of bytes
constant_pool - Array of constants
verbose - be verbose, e.g. print constant pool index
Returns:
String representation of byte code
Throws:
IOException - if a failure from reading from the bytes argument occurs

compactClassName

public static final String compactClassName(String str)
Shorten long class names, java/lang/String becomes String.

Parameters:
str - The long class name
Returns:
Compacted class name

compactClassName

public static final 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. Slashes / are converted to dots ..

Parameters:
str - The long class name
prefix - The prefix the get rid off
chopit - Flag that determines whether chopping is executed or not
Returns:
Compacted class name

compactClassName

public static final String compactClassName(String str,
                                            boolean chopit)
Shorten long class names, java/lang/String becomes java.lang.String, e.g.. If chopit is true the prefix java.lang is also removed.

Parameters:
str - The long class name
chopit - Flag that determines whether chopping is executed or not
Returns:
Compacted class name

methodSignatureToString

public static final String methodSignatureToString(String signature,
                                                   String name,
                                                   String access,
                                                   boolean chopit,
                                                   LocalVariableTable vars)
                                            throws ClassFormatException
A returntype signature represents the return value from a method. It is a series of bytes in the following grammar: ::= | V The character V indicates that the method returns no value. Otherwise, the signature indicates the type of the return value. An argument signature represents an argument passed to a method: ::= A method signature represents the arguments that the method expects, and the value that it returns. ::= () ::= * This method converts such a string into a Java type declaration like `void main(String[])' and throws a `ClassFormatException' when the parsed type is invalid.

Parameters:
signature - Method signature
name - Method name
access - Method access rights
chopit -
vars -
Returns:
Java type declaration
Throws:
ClassFormatException

replace

public static final String replace(String str,
                                   String old,
                                   String new_)
Replace all occurrences of old in str with new.

Parameters:
str - String to permute
old - String to be replaced
new_ - Replacement string
Returns:
new String object

signatureToString

public static final String signatureToString(String signature)
Converts signature to string with all class names compacted.

Parameters:
signature - to convert
Returns:
Human readable signature

signatureToString

public static final String signatureToString(String signature,
                                             boolean chopit)
The field signature represents the value of an argument to a function or the value of a variable. It is a series of bytes generated by the following grammar:
  ::= 
       ::= ||
        ::= B|C|D|F|I|J|S|Z
      ::= L;
       ::= [

 The meaning of the base types is as follows:
 B byte signed byte
 C char character
 D double double precision IEEE float
 F float single precision IEEE float
 I int integer
 J long long integer
 L; ... an object of the given class
 S short signed short
 Z boolean true or false
 [ ... array
 
This method converts this string into a Java type declaration such as `String[]' and throws a `ClassFormatException' when the parsed type is invalid.

Parameters:
signature - Class signature
chopit - Flag that determines whether chopping is executed or not
Returns:
Java type declaration
Throws:
ClassFormatException

toHexString

public static final String toHexString(byte[] bytes)
Convert bytes into hexadecimal string

Parameters:
bytes - an array of bytes to convert to hexadecimal
Returns:
bytes as hexadecimal string, e.g. 00 FA 12 ...

fillup

public static final String fillup(String str,
                                  int length,
                                  boolean left_justify,
                                  char fill)
Fillup char with up to length characters with char `fill' and justify it left or right.

Parameters:
str - string to format
length - length of desired string
left_justify - format left or right
fill - fill character
Returns:
formatted string

convertString

public static final String convertString(String label)
Escape all occurences of newline chars '\n', quotes \", etc.


Apache Tomcat 7.0.28

Copyright © 2000-2012 Apache Software Foundation. All Rights Reserved.