1 /*
2  * Javassist, a Java-bytecode translator toolkit.
3  * Copyright (C) 1999-2007 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  *
10  * Software distributed under the License is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12  * for the specific language governing rights and limitations under the
13  * License.
14  */
15 
16 package javassist.tools;
17 
18 import java.io.*;
19 import javassist.bytecode.ClassFile;
20 import javassist.bytecode.ClassFilePrinter;
21 
22 /**
23  * Dump is a tool for viewing the class definition in the given
24  * class file.  Unlike the JDK javap tool, Dump works even if
25  * the class file is broken.
26  *
27  * <p>For example,
28  * <ul><pre>% java javassist.tools.Dump foo.class</pre></ul>
29  *
30  * <p>prints the contents of the constant pool and the list of methods
31  * and fields.
32  */
33 public class Dump {
Dump()34     private Dump() {}
35 
36     /**
37      * Main method.
38      *
39      * @param args           <code>args[0]</code> is the class file name.
40      */
main(String[] args)41     public static void main(String[] args) throws Exception {
42         if (args.length != 1) {
43             System.err.println("Usage: java Dump <class file name>");
44             return;
45         }
46 
47         DataInputStream in = new DataInputStream(
48                                          new FileInputStream(args[0]));
49         ClassFile w = new ClassFile(in);
50         PrintWriter out = new PrintWriter(System.out, true);
51         out.println("*** constant pool ***");
52         w.getConstPool().print(out);
53         out.println();
54         out.println("*** members ***");
55         ClassFilePrinter.print(w, out);
56     }
57 }
58