KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > vfs > provider > compressed > CompressedFileFileObject


1 /*
2  * Copyright 2002-2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.commons.vfs.provider.compressed;
17
18 import org.apache.commons.vfs.Capability;
19 import org.apache.commons.vfs.FileName;
20 import org.apache.commons.vfs.FileObject;
21 import org.apache.commons.vfs.FileSystemException;
22 import org.apache.commons.vfs.FileType;
23 import org.apache.commons.vfs.provider.AbstractFileObject;
24
25 /**
26  * A compressed file.<br>
27  * Such a file do only have one child (the compressed filename with stripped last extension)
28  *
29  * @author <a HREF="mailto:imario@apache.org">Mario Ivankovits</a>
30  */

31 public abstract class CompressedFileFileObject
32     extends AbstractFileObject
33     implements FileObject
34 {
35     private final FileObject container;
36     private String JavaDoc[] children;
37
38     protected CompressedFileFileObject(FileName name, FileObject container, CompressedFileFileSystem fs)
39     {
40         super(name, fs);
41         this.container = container;
42
43         // todo, add getBaseName(String) to FileName
44
String JavaDoc basename = container.getName().getBaseName();
45         int pos = basename.lastIndexOf('.');
46         basename = basename.substring(0, pos);
47
48         children = new String JavaDoc[]
49         {
50             basename
51         };
52     }
53
54     /**
55      * Returns true if this file is read-only.
56      */

57     public boolean isWriteable()
58     {
59         return getFileSystem().hasCapability(Capability.WRITE_CONTENT);
60     }
61
62     /**
63      * Returns the file's type.
64      */

65     protected FileType doGetType() throws FileSystemException
66     {
67         if (getName().getPath().endsWith("/"))
68         {
69             return FileType.FOLDER;
70         }
71         else
72         {
73             return FileType.FILE;
74         }
75     }
76
77     /**
78      * Lists the children of the file.
79      */

80     protected String JavaDoc[] doListChildren()
81     {
82         return children;
83     }
84
85     /**
86      * Returns the size of the file content (in bytes). Is only called if
87      * {@link #doGetType} returns {@link FileType#FILE}.
88      */

89     protected long doGetContentSize()
90     {
91         return -1;
92     }
93
94     /**
95      * Returns the last modified time of this file.
96      */

97     protected long doGetLastModifiedTime() throws Exception JavaDoc
98     {
99         return container.getContent().getLastModifiedTime();
100     }
101
102     protected FileObject getContainer()
103     {
104         return container;
105     }
106
107     public void createFile() throws FileSystemException
108     {
109         container.createFile();
110         injectType(FileType.FILE);
111     }
112 }
113
Popular Tags