1 17 package org.apache.servicemix.bpe.util; 18 19 import java.io.BufferedOutputStream ; 20 import java.io.ByteArrayOutputStream ; 21 import java.io.File ; 22 import java.io.FileOutputStream ; 23 import java.io.OutputStreamWriter ; 24 import java.io.Writer ; 25 import java.util.jar.JarEntry ; 26 import java.util.jar.JarInputStream ; 27 28 import org.apache.servicemix.bpe.util.FileSystemJarInputStream; 29 30 import junit.framework.TestCase; 31 32 public class FileSystemJarInputStreamTest extends TestCase { 33 34 private static final int BUFFER = 2048; 35 36 public void testInputStream() throws Exception { 37 File f = new File ("target/test-data"); 38 f.mkdirs(); 39 Writer w = new OutputStreamWriter (new FileOutputStream (new File (f, "test.txt"))); 40 w.write("<hello>world</hello>"); 41 w.close(); 42 43 FileSystemJarInputStream fsjis = new FileSystemJarInputStream(f); 44 JarInputStream jis = new JarInputStream (fsjis); 45 46 JarEntry entry = jis.getNextJarEntry(); 47 assertNotNull(entry); 48 assertEquals("test.txt", entry.getName()); 49 50 BufferedOutputStream dest = null; 52 ByteArrayOutputStream baos = null; 53 int count; byte data[] = new byte[BUFFER]; 55 baos = new ByteArrayOutputStream (); 56 dest = new BufferedOutputStream (baos, BUFFER); 57 while ((count = jis.read(data, 0, BUFFER)) != -1) { 58 dest.write(data, 0, count); 59 } 60 dest.close(); 61 System.out.println(entry.getName() + ": " + baos.toString()); 62 63 assertEquals("<hello>world</hello>", baos.toString()); 64 } 65 66 } 67 | Popular Tags |