You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Dump.java 1.9KB

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