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