KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jode > obfuscator > TranslationTable


1 /* TranslationTable Copyright (C) 1999-2002 Jochen Hoenicke.
2  *
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2, or (at your option)
6  * any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * 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 JavaDoc;
23 import java.util.TreeMap JavaDoc;
24 import java.util.Iterator JavaDoc;
25
26 ///#ifndef JDK12
27
///import java.util.Comparator;
28
///#endif
29

30 import java.io.InputStream JavaDoc;
31 import java.io.InputStreamReader JavaDoc;
32 import java.io.BufferedReader JavaDoc;
33 import java.io.OutputStream JavaDoc;
34 import java.io.PrintWriter JavaDoc;
35 import java.io.IOException JavaDoc;
36
37 public class TranslationTable extends TreeMap JavaDoc {
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 JavaDoc in) throws IOException JavaDoc {
54         BufferedReader JavaDoc reader =
55       new BufferedReader JavaDoc(new InputStreamReader JavaDoc(in));
56
57     String JavaDoc line;
58         while ((line = reader.readLine()) != null) {
59         if (line.charAt(0) == '#')
60         continue;
61         int delim = line.indexOf('=');
62         String JavaDoc key = line.substring(0, delim);
63         String JavaDoc value = line.substring(delim+1);
64         put(key, value);
65     }
66     }
67
68     public void store(OutputStream JavaDoc out) throws IOException JavaDoc {
69         PrintWriter JavaDoc writer = new PrintWriter JavaDoc(out);
70     for (Iterator JavaDoc i = entrySet().iterator(); i.hasNext(); ) {
71         Map.Entry JavaDoc e = (Map.Entry JavaDoc) i.next();
72         writer.println(e.getKey()+"="+e.getValue());
73     }
74     writer.flush();
75     }
76 }
77
Popular Tags