1 25 package classycle.classfile; 26 27 import java.io.DataInputStream ; 28 import java.io.FileInputStream ; 29 import java.io.IOException ; 30 31 37 public class ConstantPoolPrinter { 38 42 public static void main(String [] args) { 43 if (args.length == 0) { 44 System.out.println( 45 "Usage: java classycle.classfile.ConstantPoolPrinter <class files>"); 46 } 47 for (int i = 0; i < args.length; i++) { 48 investigate(args[i]); 49 } 50 } 51 52 private static void investigate(String fileName) { 53 DataInputStream stream = null; 54 try { 55 stream = new DataInputStream (new FileInputStream (fileName)); 56 Constant[] pool = Constant.extractConstantPool(stream); 57 printConstantPool(pool); 58 } catch (IOException e) { 59 System.out.println(e); 60 } finally { 61 try { 62 stream.close(); 63 } catch (IOException e) { 64 } 65 } 66 } 67 68 private static void printConstantPool(Constant[] pool) { 69 for (int i = 0; i < pool.length; i++) { 70 System.out.println(i + ": " + pool[i]); 71 } 72 } 73 } | Popular Tags |