01: /*
02: * PrintClassFile.java
03: *
04: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
05: *
06: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
07: *
08: * The contents of this file are subject to the terms of either the GNU
09: * General Public License Version 2 only ("GPL") or the Common
10: * Development and Distribution License("CDDL") (collectively, the
11: * "License"). You may not use this file except in compliance with the
12: * License. You can obtain a copy of the License at
13: * http://www.netbeans.org/cddl-gplv2.html
14: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
15: * specific language governing permissions and limitations under the
16: * License. When distributing the software, include this License Header
17: * Notice in each file and include the License file at
18: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
19: * particular file as subject to the "Classpath" exception as provided
20: * by Sun in the GPL Version 2 section of the License file that
21: * accompanied this code. If applicable, add the following below the
22: * License Header, with the fields enclosed by brackets [] replaced by
23: * your own identifying information:
24: * "Portions Copyrighted [year] [name of copyright owner]"
25: *
26: * Contributor(s):
27: *
28: * The Original Software is NetBeans. The Initial Developer of the Original
29: * Software is Sun Microsystems, Inc. Portions Copyright 2000-2001 Sun
30: * Microsystems, Inc. All Rights Reserved.
31: *
32: * If you wish your version of this file to be governed by only the CDDL
33: * or only the GPL Version 2, indicate your decision by adding
34: * "[Contributor] elects to include this software in this distribution
35: * under the [CDDL or GPL Version 2] license." If you do not indicate a
36: * single choice of license, a recipient has the option to distribute
37: * your version of this file under either the CDDL, the GPL Version 2 or
38: * to extend the choice of license to its licensees as provided above.
39: * However, if you add GPL Version 2 code and therefore, elected the GPL
40: * Version 2 license, then the option applies only if the new code is
41: * made subject to such option by the copyright holder.
42: *
43: * Contributor(s): Thomas Ball
44: *
45: * Version: $Revision$
46: */
47:
48: import org.netbeans.modules.classfile.*;
49: import java.io.*;
50: import java.util.*;
51:
52: /**
53: * PrintClassFile: write a class as a println statement.
54: *
55: * @author Thomas Ball
56: */
57: public class PrintClassFile {
58: String this Class;
59:
60: PrintClassFile(String spec) {
61: this Class = spec;
62: }
63:
64: void print(PrintStream out) throws IOException {
65: InputStream is = new FileInputStream(this Class);
66: ClassFile cfile = new ClassFile(is);
67: out.println(cfile);
68: }
69:
70: /**
71: * An error routine which displays the command line usage
72: * before exiting.
73: */
74: public static void usage() {
75: System.err
76: .println("usage: java PrintClassFile <file> [ <file> ...]");
77: System.exit(1);
78: }
79:
80: public static void main(String[] args) {
81: if (args.length == 0)
82: usage();
83:
84: for (int i = 0; i < args.length; i++) {
85: if (args[i].charAt(0) == '-')
86: usage();
87: else {
88: try {
89: PrintClassFile pc = new PrintClassFile(args[i]);
90: pc.print(System.out);
91: } catch (IOException e) {
92: System.err.println("error accessing \"" + args[i]
93: + "\": " + e.toString());
94: }
95: }
96: }
97: }
98: }
|