1 30 package org.objectweb.asm.optimizer; 31 32 import java.io.File ; 33 import java.io.FileOutputStream ; 34 import java.io.IOException ; 35 import java.io.InputStream ; 36 import java.util.Enumeration ; 37 import java.util.zip.ZipEntry ; 38 import java.util.zip.ZipFile ; 39 import java.util.zip.ZipOutputStream ; 40 41 46 public class JarOptimizer { 47 48 public static void main(final String [] args) throws IOException { 49 File f = new File (args[0]); 50 optimize(f); 51 } 52 53 static void optimize(final File f) throws IOException { 54 if (f.isDirectory()) { 55 File [] files = f.listFiles(); 56 for (int i = 0; i < files.length; ++i) { 57 optimize(files[i]); 58 } 59 } else if (f.getName().endsWith(".jar")) { 60 File g = new File (f.getParentFile(), f.getName() + ".new"); 61 ZipFile zf = new ZipFile (f); 62 ZipOutputStream out = new ZipOutputStream (new FileOutputStream (g)); 63 Enumeration e = zf.entries(); 64 byte[] buf = new byte[10000]; 65 while (e.hasMoreElements()) { 66 ZipEntry ze = (ZipEntry ) e.nextElement(); 67 if (ze.isDirectory()) { 68 continue; 69 } 70 out.putNextEntry(ze); 71 InputStream is = zf.getInputStream(ze); 72 int n; 73 do { 74 n = is.read(buf, 0, buf.length); 75 if (n != -1) { 76 out.write(buf, 0, n); 77 } 78 } while (n != -1); 79 out.closeEntry(); 80 } 81 out.close(); 82 zf.close(); 83 f.delete(); 84 g.renameTo(f); 85 } 86 } 87 } 88 | Popular Tags |