01: /* TranslationTable Copyright (C) 1999-2002 Jochen Hoenicke.
02: *
03: * This program is free software; you can redistribute it and/or modify
04: * it under the terms of the GNU General Public License as published by
05: * the Free Software Foundation; either version 2, or (at your option)
06: * any later version.
07: *
08: * This program is distributed in the hope that it will be useful,
09: * but WITHOUT ANY WARRANTY; without even the implied warranty of
10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11: * GNU General Public License for more details.
12: *
13: * You should have received a copy of the GNU General Public License
14: * along with this program; see the file COPYING. If not, write to
15: * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
16: *
17: * $Id: TranslationTable.java.in,v 1.1.2.2 2002/05/28 17:34:14 hoenicke Exp $
18: */
19:
20: package jode.obfuscator;
21:
22: import java.util.Map;
23: import java.util.TreeMap;
24: import java.util.Iterator;
25:
26: ///#ifndef JDK12
27: ///import java.util.Comparator;
28: ///#endif
29:
30: import java.io.InputStream;
31: import java.io.InputStreamReader;
32: import java.io.BufferedReader;
33: import java.io.OutputStream;
34: import java.io.PrintWriter;
35: import java.io.IOException;
36:
37: public class TranslationTable extends TreeMap {
38:
39: ///#ifndef JDK12
40: /// public TranslationTable() {
41: /// super(createStringComparator());
42: /// }
43: ///
44: /// private static Comparator createStringComparator() {
45: /// return new Comparator() {
46: /// public int compare(Object o1, Object o2) {
47: /// return ((String) o1).compareTo((String) o2);
48: /// }
49: /// };
50: /// }
51: ///#endif
52:
53: public void load(InputStream in) throws IOException {
54: BufferedReader reader = new BufferedReader(
55: new InputStreamReader(in));
56:
57: String line;
58: while ((line = reader.readLine()) != null) {
59: if (line.charAt(0) == '#')
60: continue;
61: int delim = line.indexOf('=');
62: String key = line.substring(0, delim);
63: String value = line.substring(delim + 1);
64: put(key, value);
65: }
66: }
67:
68: public void store(OutputStream out) throws IOException {
69: PrintWriter writer = new PrintWriter(out);
70: for (Iterator i = entrySet().iterator(); i.hasNext();) {
71: Map.Entry e = (Map.Entry) i.next();
72: writer.println(e.getKey() + "=" + e.getValue());
73: }
74: writer.flush();
75: }
76: }
|