added OptimizeCore
[org.ibex.core.git] / src / org / ibex / core / OptimizeCore.java
1 package org.ibex.core;
2 import org.ibex.classgen.*;
3 import java.io.*;
4 import java.util.*;
5 import java.util.zip.*;
6
7 public class OptimizeCore {
8     public static void main(String[] s) throws Exception {
9         File outf = new File(s[0] + "-");
10         File inf = new File(s[0]);
11         ZipOutputStream out = new ZipOutputStream(new FileOutputStream(outf));
12         ZipInputStream zis = new ZipInputStream(new FileInputStream(inf));
13         for(;;) {
14             ZipEntry ze = zis.getNextEntry();
15             if (ze==null) break;
16             out.putNextEntry(ze);
17             String name = ze.getName();
18             if (!name.endsWith(".class")) {
19                 byte b[] = new byte[1024];
20                 for(;;) {
21                     int numread = zis.read(b, 0, b.length);
22                     if (numread==-1) break;
23                     out.write(b, 0, numread);
24                 }
25                 continue;
26             }
27             System.out.println("updating " + name.substring(0, name.length()-6).replace('$','.').replace('/','.'));
28             ClassFile cf = new ClassFile(new DataInputStream(zis));
29             cf.dump(out);
30         }
31         out.close();
32         outf.renameTo(inf);
33     }
34 }