01: /*
02: * Javassist, a Java-bytecode translator toolkit.
03: * Copyright (C) 1999-2006 Shigeru Chiba. All Rights Reserved.
04: *
05: * The contents of this file are subject to the Mozilla Public License Version
06: * 1.1 (the "License"); you may not use this file except in compliance with
07: * the License. Alternatively, the contents of this file may be used under
08: * the terms of the GNU Lesser General Public License Version 2.1 or later.
09: *
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.ClassFileWriter;
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 {
34: private Dump() {
35: }
36:
37: /**
38: * Main method.
39: *
40: * @param args <code>args[0]</code> is the class file name.
41: */
42: public static void main(String[] args) throws Exception {
43: if (args.length != 1) {
44: System.err.println("Usage: java Dump <class file name>");
45: return;
46: }
47:
48: DataInputStream in = new DataInputStream(new FileInputStream(
49: args[0]));
50: ClassFile w = new ClassFile(in);
51: PrintWriter out = new PrintWriter(System.out, true);
52: out.println("*** constant pool ***");
53: w.getConstPool().print(out);
54: out.println();
55: out.println("*** members ***");
56: ClassFileWriter.print(w, out);
57: }
58: }
|