1 20 21 package com.tonicsystems.jarjar.util; 22 23 import java.util.jar.JarEntry ; 24 import java.util.jar.JarFile ; 25 import java.util.jar.JarOutputStream ; 26 import java.util.Enumeration ; 27 import java.util.zip.ZipOutputStream ; 28 import java.io.*; 29 30 public class StandaloneJarProcessor 31 { 32 public static void run(File from, File to, JarProcessor proc) throws IOException { 33 JarFile in = new JarFile (from); 34 JarOutputStream out = new JarOutputStream (new FileOutputStream(to)); 35 byte[] buf = new byte[0x2000]; 36 EntryStruct struct = new EntryStruct(); 37 Enumeration e = in.entries(); 38 while (e.hasMoreElements()) { 39 JarEntry entry = (JarEntry )e.nextElement(); 40 struct.in = in.getInputStream(entry); 41 struct.name = entry.getName(); 42 struct.time = entry.getTime(); 43 struct.file = from; 44 if (proc.process(struct)) { 45 entry = new JarEntry (struct.name); 46 entry.setTime(struct.time); 47 entry.setCompressedSize(-1); 48 out.putNextEntry(entry); 49 pipe(struct.in, out, buf); 50 struct.in.close(); 51 } 52 } 53 out.close(); 54 out = null; 55 } 56 57 private static void pipe(InputStream is, OutputStream out, byte[] buf) throws IOException { 58 for (;;) { 59 int amt = is.read(buf); 60 if (amt < 0) 61 break; 62 out.write(buf, 0, amt); 63 } 64 } 65 } 66 | Popular Tags |