1 17 package org.apache.servicemix.bpe.util; 18 19 import java.io.File ; 20 import java.io.IOException ; 21 import java.io.InputStream ; 22 import java.io.PipedInputStream ; 23 import java.io.PipedOutputStream ; 24 import java.util.jar.JarOutputStream ; 25 26 import org.apache.servicemix.jbi.util.FileUtil; 27 28 public class FileSystemJarInputStream extends InputStream implements Runnable { 29 30 private File root; 31 private PipedInputStream input; 32 private PipedOutputStream output; 33 private Thread runner; 34 private IOException exception; 35 36 public FileSystemJarInputStream(File root) throws IOException { 37 this.root = root; 38 input = new PipedInputStream (); 39 output = new PipedOutputStream (input); 40 } 41 42 public int read() throws IOException { 43 if (runner == null) { 44 runner = new Thread (this); 45 runner.setDaemon(true); 46 runner.start(); 47 } 48 if (exception != null) { 49 throw exception; 50 } 51 return input.read(); 52 } 53 54 public void run() { 55 try { 56 JarOutputStream jos = new JarOutputStream (output); 57 FileUtil.zipDir(root.getAbsolutePath(), jos, ""); 58 jos.close(); 59 } catch (IOException e) { 60 exception = e; 61 try { 62 output.close(); 63 } catch (IOException e2) { 64 e2.printStackTrace(); 65 } 66 } 67 } 68 69 } 70 | Popular Tags |