/Users/lyon/j4p/src/javassist/Dump.java
|
1 /*
2 * Javassist, a Java-bytecode translator toolkit.
3 * Copyright (C) 1999-2003 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;
17
18 import java.io.*;
19
20 import javassist.bytecode.ClassFile;
21 import javassist.bytecode.ClassFileWriter;
22
23 /**
24 * Dump is a tool for viewing the class definition in the given
25 * class file. Unlike the JDK javap tool, Dump works even if
26 * the class file is broken.
27 *
28 * <p>For example,
29 * <ul><pre>% java javassist.Dump foo.class</pre></ul>
30 *
31 * <p>prints the contents of the constant pool and the list of methods
32 * and fields.
33 */
34 public class Dump {
35 private Dump() {
36 }
37
38 /**
39 * Main method.
40 *
41 * @param args[0] class file name.
42 */
43 public static void main(String[] args) throws Exception {
44 if (args.length != 1) {
45 System.err.println("Usage: java Dump <class file name>");
46 return;
47 }
48
49 DataInputStream in = new DataInputStream(
50 new FileInputStream(args[0]));
51 ClassFile w = new ClassFile(in);
52 PrintWriter out = new PrintWriter(System.out, true);
53 out.println("*** constant pool ***");
54 w.getConstPool().print(out);
55 out.println();
56 out.println("*** members ***");
57 ClassFileWriter.print(w, out);
58 }
59 }
60