| Code with Finding: |
class Utility {
/**
* 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.
*
* @param code byte code array
* @param constant_pool Array of constants
* @param index offset in `code' array
* <EM>(number of opcodes, not bytes!)</EM>
* @param length number of opcodes to decompile, -1 for all
* @param verbose be verbose, e.g. print constant pool index
* @return String representation of byte codes
*/
public static String codeToString( byte[] code, ConstantPool constant_pool, int index,
int length, boolean verbose ) {
StringBuilder buf = new StringBuilder(code.length * 20); // Should be sufficient // CHECKSTYLE IGNORE MagicNumber
ByteSequence stream = new ByteSequence(code);
try {
for (int i = 0; i < index; i++) {
codeToString(stream, constant_pool, verbose);
}
for (int i = 0; stream.available() > 0; i++) {
if ((length < 0) || (i < length)) {
String indices = fillup(stream.getIndex() + ":", 6, true, ' ');
buf.append(indices).append(codeToString(stream, constant_pool, verbose))
.append('\n');
}
}
} catch (IOException e) {
System.out.println(buf.toString());
e.printStackTrace();
throw new ClassFormatException("Byte code error: " + e, e);
}
return buf.toString();
}
}
class Utility {
/**
* Shorten long class name <em>str</em>, i.e., chop off the <em>prefix</em>,
* if the
* class name starts with this string and the flag <em>chopit</em> is true.
* Slashes <em>/</em> are converted to dots <em>.</em>.
*
* @param str The long class name
* @param prefix The prefix the get rid off
* @param chopit Flag that determines whether chopping is executed or not
* @return Compacted class name
*/
public static String compactClassName( String str, String prefix, boolean chopit ) {
int len = prefix.length();
str = str.replace('/', '.'); // Is `/' on all systems, even DOS
if (chopit) {
// If string starts with `prefix' and contains no further dots
if (str.startsWith(prefix) && (str.substring(len).indexOf('.') == -1)) {
str = str.substring(len);
}
}
return str;
}
}
|