KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonicsystems > jarjar > StringDumper


1 /*
2   Jar Jar Links - A utility to repackage and embed Java libraries
3   Copyright (C) 2004 Tonic Systems, Inc.
4
5   This program is free software; you can redistribute it and/or modify
6   it under the terms of the GNU General Public License as published by
7   the Free Software Foundation; either version 2 of the License, or
8   (at your option) any later version.
9
10   This program is distributed in the hope that it will be useful,
11   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13   GNU General Public License for more details.
14
15   You should have received a copy of the GNU General Public License
16   along with this program; see the file COPYING. if not, write to
17   the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18   Boston, MA 02111-1307 USA
19 */

20
21 package com.tonicsystems.jarjar;
22
23 import com.tonicsystems.jarjar.util.*;
24 import java.io.*;
25 import org.objectweb.asm.*;
26
27 class StringDumper
28 {
29     public StringDumper() {
30     }
31
32     public void run(String JavaDoc classPath, final PrintWriter pw) throws IOException {
33         try {
34             StringVisitor sv = new StringVisitor() {
35                 private String JavaDoc className;
36                 private boolean needName;
37                 public void visitStart(String JavaDoc className) {
38                     this.className = className;
39                     needName = true;
40                 }
41                 public void visitString(String JavaDoc value, int line) {
42                     if (value.length() > 0) {
43                         if (needName) {
44                             pw.println(className.replace('/', '.'));
45                             needName = false;
46                         }
47                         pw.print("\t");
48                         if (line >= 0)
49                             pw.print(line + ": ");
50                         pw.print(IoUtils.escapeStringLiteral(value));
51                         pw.println();
52                     }
53                 }
54                 public void visitEnd() {
55                     pw.flush();
56                 }
57             };
58             StringReader stringReader = new StringReader(sv);
59             ClassPathIterator cp = new ClassPathIterator(classPath);
60             while (cp.hasNext()) {
61                 new ClassReader(cp.getInputStream(cp.next())).accept(stringReader, false);
62             }
63         } catch (RuntimeIOException e) {
64             throw (IOException)e.getCause();
65         }
66     }
67 }
68
Popular Tags