1 16 package org.apache.commons.vfs.provider.bzip2; 17 18 import java.io.IOException ; 19 import java.io.InputStream ; 20 import java.io.OutputStream ; 21 22 import org.apache.commons.vfs.FileName; 23 import org.apache.commons.vfs.FileObject; 24 import org.apache.commons.vfs.FileSystemException; 25 import org.apache.commons.vfs.provider.compressed.CompressedFileFileObject; 26 import org.apache.commons.vfs.provider.compressed.CompressedFileFileSystem; 27 import org.apache.tools.bzip2.CBZip2InputStream; 28 import org.apache.tools.bzip2.CBZip2OutputStream; 29 30 35 public class Bzip2FileObject extends CompressedFileFileObject 36 { 37 protected Bzip2FileObject(FileName name, FileObject container, CompressedFileFileSystem fs) 38 { 39 super(name, container, fs); 40 } 41 42 protected InputStream doGetInputStream() throws Exception 43 { 44 InputStream is = getContainer().getContent().getInputStream(); 46 return wrapInputStream(getName().getURI(), is); 47 } 48 49 public static InputStream wrapInputStream(final String name, final InputStream is) throws IOException 50 { 51 final int b1 = is.read(); 52 final int b2 = is.read(); 53 if (b1 != 'B' || b2 != 'Z') 54 { 55 throw new FileSystemException("vfs.provider.compressedFile/not-a-compressedFile-file.error", name); 56 } 57 return new CBZip2InputStream(is); 58 } 59 60 protected OutputStream doGetOutputStream(boolean bAppend) throws Exception 61 { 62 OutputStream os = getContainer().getContent().getOutputStream(false); 63 os.write('B'); 64 os.write('Z'); 65 66 return new CBZip2OutputStream(os); 67 } 68 } 69 | Popular Tags |