1 32 33 package com.jeantessier.dependencyfinder.cli; 34 35 import java.io.*; 36 37 import com.jeantessier.dependencyfinder.*; 38 39 public class ClassDump { 40 public static void main(String [] args) throws Exception { 41 if (args.length == 0) { 42 System.out.println(ClassDump.class.getName() + ":"); 43 dumpClass(ClassDump.class); 44 } else { 45 for (int i=0; i<args.length; i++) { 46 System.out.println(args[i] + ":"); 47 dumpClass(args[i]); 48 } 49 } 50 } 51 52 public static void dumpClass(String classname) throws ClassNotFoundException , IOException { 53 dumpClass(Class.forName(classname)); 54 } 55 56 public static void dumpClass(Class c) throws IOException { 57 String resource = c.getName().substring(c.getName().lastIndexOf(".") + 1) + ".class"; 58 System.out.println(resource + " -> " + c.getResource(resource)); 59 dumpClass(c.getResourceAsStream(resource)); 60 } 61 62 public static void dumpClass(InputStream in) throws IOException { 63 dumpClass(new DataInputStream(in)); 64 } 65 66 public static void dumpClass(DataInputStream in) { 67 int count = 0; 68 try { 69 while (true) { 70 byte b = in.readByte(); 71 72 Hex.print(System.out, b); 73 74 count++; 75 76 if ((count % 4) == 0) { 77 System.out.print(' '); 78 } 79 80 if ((count % 32) == 0) { 81 System.out.println(); 82 count = 0; 83 } 84 } 85 } catch (IOException ex) { 86 } finally { 88 System.out.println(); 89 } 90 } 91 } 92 | Popular Tags |