1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.vfs2.provider.bzip2;
18
19 import java.io.IOException;
20 import java.io.InputStream;
21 import java.io.OutputStream;
22
23 import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream;
24 import org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream;
25 import org.apache.commons.vfs2.FileObject;
26 import org.apache.commons.vfs2.provider.AbstractFileName;
27 import org.apache.commons.vfs2.provider.compressed.CompressedFileFileObject;
28 import org.apache.commons.vfs2.provider.compressed.CompressedFileFileSystem;
29
30
31
32
33 public class Bzip2FileObject extends CompressedFileFileObject<Bzip2FileSystem> {
34
35
36
37
38
39
40
41
42
43
44 @Deprecated
45 protected Bzip2FileObject(final AbstractFileName name, final FileObject container,
46 final CompressedFileFileSystem fs) {
47 super(name, container, cast(fs));
48 }
49
50 protected Bzip2FileObject(final AbstractFileName name, final FileObject container, final Bzip2FileSystem fs) {
51 super(name, container, fs);
52 }
53
54 @Override
55 protected InputStream doGetInputStream(final int bufferSize) throws Exception {
56
57 return wrapInputStream(getName().getURI(), getContainer().getContent().getInputStream(bufferSize));
58 }
59
60 public static InputStream wrapInputStream(final String name, final InputStream inputStream) throws IOException {
61 return new BZip2CompressorInputStream(inputStream);
62 }
63
64 @Override
65 protected OutputStream doGetOutputStream(final boolean bAppend) throws Exception {
66 return new BZip2CompressorOutputStream(getContainer().getContent().getOutputStream(false));
67 }
68
69 private static Bzip2FileSystem cast(final CompressedFileFileSystem fs) {
70 if (fs instanceof Bzip2FileSystem) {
71 return (Bzip2FileSystem) fs;
72 }
73 throw new IllegalArgumentException("Bzip2FileObject requires a Bzip2FileSystem implementation");
74 }
75 }