1 /* 2 * Javassist, a Java-bytecode translator toolkit. 3 * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 * 5 * The contents of this file are subject to the Mozilla Public License Version 6 * 1.1 (the "License"); you may not use this file except in compliance with 7 * the License. Alternatively, the contents of this file may be used under 8 * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 * or the Apache License Version 2.0. 10 * 11 * Software distributed under the License is distributed on an "AS IS" basis, 12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 * for the specific language governing rights and limitations under the 14 * License. 15 */ 16 17 package javassist.tools; 18 19 import java.io.DataInputStream; 20 import java.io.FileInputStream; 21 import java.io.PrintWriter; 22 23 import javassist.bytecode.ClassFile; 24 import javassist.bytecode.ClassFilePrinter; 25 26 /** 27 * Dump is a tool for viewing the class definition in the given 28 * class file. Unlike the JDK javap tool, Dump works even if 29 * the class file is broken. 30 * 31 * <p>For example, 32 * <pre>% java javassist.tools.Dump foo.class</pre> 33 * 34 * <p>prints the contents of the constant pool and the list of methods 35 * and fields. 36 */ 37 public class Dump { Dump()38 private Dump() {} 39 40 /** 41 * Main method. 42 * 43 * @param args <code>args[0]</code> is the class file name. 44 */ main(String[] args)45 public static void main(String[] args) throws Exception { 46 if (args.length != 1) { 47 System.err.println("Usage: java Dump <class file name>"); 48 return; 49 } 50 51 DataInputStream in = new DataInputStream( 52 new FileInputStream(args[0])); 53 ClassFile w = new ClassFile(in); 54 PrintWriter out = new PrintWriter(System.out, true); 55 out.println("*** constant pool ***"); 56 w.getConstPool().print(out); 57 out.println(); 58 out.println("*** members ***"); 59 ClassFilePrinter.print(w, out); 60 } 61 } 62