Source code: com/chaoswg/xtc4y/util/ClassFilePrinter.java
1
2 //$Header: /cvsroot/xtc4y/xtc4y/src/com/chaoswg/xtc4y/util/ClassFilePrinter.java,v 1.2 2003/08/26 12:50:50 toggm Exp $
3 /******************************************************************************
4 * XTC4y - eXtreme Testing Collection 4 you *
5 * -------------------------------------------------------------------------- *
6 * URL: http://www.chaoswg.com/xtc4y *
7 * Author: Mike Toggweiler (2.dog@gmx.ch) *
8 * *
9 * Last Updated: $Date: 2003/08/26 12:50:50 $, by $Author: toggm $ *
10 * Version: $Revision: 1.2 $ *
11 * -------------------------------------------------------------------------- *
12 * COPYRIGHT: (c) 2003 by Mike Toggweiler *
13 * *
14 * This program is free software; you can redistribute it and/or modify *
15 * it under the terms of the GNU General Public License as published by *
16 * the Free Software Foundation; either version 2 of the License, or *
17 * (at your option) any later version. *
18 *****************************************************************************/
19 package com.chaoswg.xtc4y.util;
20
21 import java.io.DataInputStream;
22 import java.io.FileInputStream;
23 import java.io.InputStream;
24 import java.io.IOException;
25
26 import com.chaoswg.xtc4y.classdesc.ClassDescriptor;
27
28 /**
29 * This util class simple prints the content of a classfile onto the standard
30 * output stream
31 * @author Mike Toggweiler
32 **/
33 public class ClassFilePrinter {
34 public ClassFilePrinter() {
35 }
36
37 /**
38 * Print the content of a class onto the standard output stream
39 * @param className the name of the class to print
40 **/
41 public void print(String className) throws IOException {
42 //try to load class through the current resources
43 InputStream is = new FileInputStream(className);
44 if (is == null) {
45 throw new IOException("Couldn't find resource for name:"+
46 className);
47 }
48
49 //load class through classDescriptor
50 DataInputStream dis = new DataInputStream(is);
51 ClassDescriptor descriptor = new ClassDescriptor(dis);
52 dis.close();
53
54 System.out.println("Class: " + className + "\n" + descriptor);
55 }
56
57 /**
58 * Run this class with the filename as the only argument
59 **/
60 public static void main(String[] argv) throws Exception {
61 ClassFilePrinter printer = new ClassFilePrinter();
62 printer.print(argv[0]);
63 }
64 }