01: package tide.utils;
02:
03: import tide.bytecode.DecompiledClass;
04: import java.util.*;
05: import java.io.*;
06: import java.nio.channels.*;
07: import java.nio.*;
08: import snow.utils.storage.FileUtils;
09:
10: public final class BytecodeUtils {
11: private BytecodeUtils() {
12: }
13:
14: /** Uses javap to "decompile" a class.
15: * shows code, private methods and tables.
16: */
17: public static String getClassSourceOutlineFromByteCode(String name,
18: InputStream classContent, File javapExecutable)
19: throws Exception {
20: try {
21: if (!javapExecutable.exists())
22: throw new Exception("javap tool no found: "
23: + javapExecutable);
24:
25: // [May2007] Thanks Mike K.
26: final File temp = new File(System
27: .getProperty("java.io.tmpdir"), name);
28: temp.deleteOnExit();
29:
30: FileUtils.writeToFile(classContent, temp);
31:
32: DecompiledClass dc = new DecompiledClass(name.substring(0,
33: name.length() - 6), temp.getParentFile(),
34: javapExecutable, true);
35:
36: return dc.toString();
37: /*
38: List<String> execCommand = new ArrayList<String>();
39: execCommand.add( javapExecutable.getAbsolutePath() );
40: execCommand.add( "-private" );
41: execCommand.add( "-l" ); // shows the names and lines tables (if compiled with "-g")
42: execCommand.add( "-c" );
43: execCommand.add( name.substring(0, name.length()-6) ); // without ".class" !!
44:
45: // Waits !
46: String completeResponse = ProcessUtils.readWholeProcessStack(execCommand, temp.getParentFile());
47:
48: return completeResponse;
49: */
50: } catch (Exception e) {
51: throw e;
52: } finally {
53: if (classContent != null) {
54: try {
55: classContent.close();
56: } catch (Exception ignore) {
57: }
58: }
59: }
60: }
61: }
|