KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SOFA > Tools > Resolver > TestMain


1 /* $Id: TestMain.java,v 1.2 2004/05/20 14:23:53 bures Exp $ */
2 package SOFA.Tools.Resolver;
3
4 import java.io.BufferedReader JavaDoc;
5 import java.io.FileInputStream JavaDoc;
6 import java.io.FileOutputStream JavaDoc;
7 import java.io.FileReader JavaDoc;
8
9 /** Testing main class.
10   *
11   * @author Petr Hnetynka
12   */

13 public class TestMain {
14   /** main method
15     *
16     * @param argv 1st argument - translation table, next arguments - class files
17     * @throws Exception
18     */

19   public static final void main(String JavaDoc[] argv) throws Exception JavaDoc {
20     java.util.Hashtable JavaDoc trTable = readTable(argv[0]);
21     Resolver resolver = new Resolver(trTable);
22     for(int i=1; i<argv.length; i++) {
23       String JavaDoc newName = (String JavaDoc) trTable.get(argv[i].substring(0, argv[i].length()-6));
24       if (newName == null) {
25         newName = argv[i].substring(0, argv[i].length()-6);
26         System.out.println("WARNING: file "+argv[i]+" will be rewritten.");
27       }
28       System.out.print("Processing file "+argv[i]+"...");
29       FileInputStream JavaDoc is = new FileInputStream JavaDoc(argv[i]);
30       byte[] b = resolver.process(is);
31       is.close();
32       FileOutputStream JavaDoc os = new FileOutputStream JavaDoc(newName+".class");
33       os.write(b);
34       os.close();
35       System.out.println("OK");
36     }
37   }
38
39   private static java.util.Hashtable JavaDoc readTable(String JavaDoc fname) throws Exception JavaDoc {
40     java.util.Hashtable JavaDoc trTable = new java.util.Hashtable JavaDoc();
41     BufferedReader JavaDoc ir = new BufferedReader JavaDoc(new FileReader JavaDoc(fname));
42     String JavaDoc ln;
43     while ((ln = ir.readLine()) != null) {
44       int sp = ln.indexOf(' ');
45       if (sp != -1)
46         trTable.put(ln.substring(0,sp), ln.substring(sp+1));
47     }
48     ir.close();
49     return trTable;
50   }
51 }
52
Popular Tags