1 18 package org.apache.tools.ant.types.resources; 19 20 import java.io.InputStream ; 21 import java.io.IOException ; 22 import java.io.OutputStream ; 23 24 import org.apache.tools.bzip2.CBZip2InputStream; 25 import org.apache.tools.bzip2.CBZip2OutputStream; 26 27 35 public class BZip2Resource extends CompressedResource { 36 private static final char[] MAGIC = new char[] {'B', 'Z'}; 37 38 39 public BZip2Resource() { 40 } 41 42 46 public BZip2Resource(org.apache.tools.ant.types.ResourceCollection other) { 47 super(other); 48 } 49 50 56 protected InputStream wrapStream(InputStream in) throws IOException { 57 for (int i = 0; i < MAGIC.length; i++) { 58 if (in.read() != MAGIC[i]) { 59 throw new IOException ("Invalid bz2 stream."); 60 } 61 } 62 return new CBZip2InputStream(in); 63 } 64 65 71 protected OutputStream wrapStream(OutputStream out) throws IOException { 72 for (int i = 0; i < MAGIC.length; i++) { 73 out.write(MAGIC[i]); 74 } 75 return new CBZip2OutputStream(out); 76 } 77 78 82 protected String getCompressionName() { 83 return "Bzip2"; 84 } 85 } 86 | Popular Tags |