1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.vfs.provider.compressed;
18
19 import org.apache.commons.vfs.Capability;
20 import org.apache.commons.vfs.FileName;
21 import org.apache.commons.vfs.FileObject;
22 import org.apache.commons.vfs.FileSystemException;
23 import org.apache.commons.vfs.FileType;
24 import org.apache.commons.vfs.provider.AbstractFileObject;
25
26 /***
27 * A compressed file.<br>
28 * Such a file do only have one child (the compressed filename with stripped last extension)
29 *
30 * @author <a href="mailto:imario@apache.org">Mario Ivankovits</a>
31 * @version $Revision: 480428 $ $Date: 2006-11-29 07:15:24 +0100 (Mi, 29 Nov 2006) $
32 */
33 public abstract class CompressedFileFileObject
34 extends AbstractFileObject
35 implements FileObject
36 {
37 private final FileObject container;
38 private String[] children;
39
40 protected CompressedFileFileObject(FileName name, FileObject container, CompressedFileFileSystem fs)
41 {
42 super(name, fs);
43 this.container = container;
44
45
46 String basename = container.getName().getBaseName();
47 int pos = basename.lastIndexOf('.');
48 basename = basename.substring(0, pos);
49
50 children = new String[]
51 {
52 basename
53 };
54 }
55
56 /***
57 * Determines if this file can be written to.
58 *
59 * @return <code>true</code> if this file is writeable, <code>false</code> if not.
60 */
61 public boolean isWriteable() throws FileSystemException
62 {
63 return getFileSystem().hasCapability(Capability.WRITE_CONTENT);
64 }
65
66 /***
67 * Returns the file's type.
68 */
69 protected FileType doGetType() throws FileSystemException
70 {
71 if (getName().getPath().endsWith("/"))
72 {
73 return FileType.FOLDER;
74 }
75 else
76 {
77 return FileType.FILE;
78 }
79 }
80
81 /***
82 * Lists the children of the file.
83 */
84 protected String[] doListChildren()
85 {
86 return children;
87 }
88
89 /***
90 * Returns the size of the file content (in bytes). Is only called if
91 * {@link #doGetType} returns {@link FileType#FILE}.
92 */
93 protected long doGetContentSize()
94 {
95 return -1;
96 }
97
98 /***
99 * Returns the last modified time of this file.
100 */
101 protected long doGetLastModifiedTime() throws Exception
102 {
103 return container.getContent().getLastModifiedTime();
104 }
105
106 protected FileObject getContainer()
107 {
108 return container;
109 }
110
111 public void createFile() throws FileSystemException
112 {
113 container.createFile();
114 injectType(FileType.FILE);
115 }
116 }