1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 package org.objectledge.filesystem;
30
31 import java.io.IOException;
32 import java.io.InputStream;
33 import java.io.OutputStream;
34 import java.net.MalformedURLException;
35 import java.net.URL;
36 import java.util.Set;
37
38 /***
39 * Specifies the contract between FileSystem abstarction and its concrete delegates.
40 *
41 * @author <a href="Rafal.Krzewski">rafal@caltha.pl</a>
42 * @version $Id: FileSystemProvider.java,v 1.7 2005/10/06 08:38:38 rafal Exp $
43 */
44 public interface FileSystemProvider
45 {
46 /***
47 * Returns the name of the provider.
48 *
49 * @return name of the provider.
50 */
51 public String getName();
52
53 /***
54 * Returns <code>true</code> if the provider is readonly.
55 *
56 * @return <code>true</code> if the provider is readonly.
57 */
58 public boolean isReadOnly();
59
60 /***
61 * Returns <code>true</code> if the given path contains acceptable characters.
62 *
63 * @param path the path.
64 * @return <code>true</code> if the given path contains acceptable characters.
65 */
66 public boolean checkPathChars(String path);
67
68 /***
69 * Checks if the given file or directory exists.
70 *
71 * @param path the path.
72 * @return <code>true</code> if the given file or directory exists.
73 */
74 public boolean exists(String path);
75
76 /***
77 * Checks if the given pathname points to an ordinary file.
78 *
79 * @param path the path
80 * @return <code>true</code> if the given pathname points to a directory.
81 */
82 public boolean isFile(String path);
83
84 /***
85 * Checks if the given pathname points to a directory.
86 *
87 * @param path the path
88 * @return <code>true</code> if the given pathname points to a directory.
89 */
90 public boolean isDirectory(String path);
91
92 /***
93 * Checks if the application is allowed to read given file
94 * or directory.
95 *
96 * @param path the path.
97 * @return <code>true</code> if the application is allowed to read given
98 * file or directory.
99 */
100 public boolean canRead(String path);
101
102 /***
103 * Checks if the application is allowed to write given file
104 * or directory.
105 *
106 * @param path the path.
107 * @return <code>true</code> if the application is allowed to write given
108 * file or directory.
109 */
110 public boolean canWrite(String path);
111
112 /***
113 * Lists the files and directories inside a directory.
114 *
115 * @param dir the directory.
116 * @return a list of names.
117 * @throws IOException if <code>dir</code> does not exist
118 * or is not a directory.
119 */
120 public Set<String> list(String dir)
121 throws IOException;
122
123 /***
124 * Atomically creates a new, empty file named by this abstract pathname if
125 * and only if a file with this name does not yet exist.
126 *
127 * <p>The check for the existence of the file and the creation of the file
128 * if it does not exist are a single operation that is atomic with respect
129 * to all other filesystem activities that might affect the file.</p>
130 *
131 * @param path the pathname of the file to create.
132 * @return <code>true</code> if the named file does not exist and was
133 * successfully created; <code>false</code> if the named file
134 * already exists.
135 * @throws UnsupportedCharactersInFilePathException if the given path contains characters
136 * incompatible with underlying filesystem.
137 * @throws IOException if the operation fails.
138 */
139 public boolean createNewFile(String path)
140 throws IOException, UnsupportedCharactersInFilePathException;
141
142 /***
143 * Creates a directory, and all necceray parent directories.
144 *
145 * @param path the path.
146 * @throws UnsupportedCharactersInFilePathException if the given path contains characters
147 * incompatible with underlying filesystem.
148 * @throws IOException if the operation fails.
149 */
150 public void mkdirs(String path)
151 throws IOException, UnsupportedCharactersInFilePathException;
152
153 /***
154 * Deletes a file or directory.
155 *
156 * <p>Directories must be empty when being deleted.</p>
157 *
158 * @param path the path.
159 * @throws IOException if the operation fails.
160 */
161 public void delete(String path)
162 throws IOException;
163
164 /***
165 * Atomically renames a file or directory.
166 *
167 * @param from source path.
168 * @param to destination path.
169 * @throws UnsupportedCharactersInFilePathException if the given destination path contains
170 * characters incompatible with underlying filesystem.
171 * @throws IOException if the operation fails.
172 */
173 public void rename(String from, String to)
174 throws IOException, UnsupportedCharactersInFilePathException;
175
176 /***
177 * Opens an input stream for reading a file.
178 *
179 * @param path the path.
180 * @return the InputStream or null if not available.
181 */
182 public InputStream getInputStream(String path);
183
184 /***
185 * Opens an output stream for writing to file.
186 *
187 * @param path the path.
188 * @param append <code>true</code> to append, <code>false</code> to truncate.
189 * @return the InputStream or null if not available.
190 */
191 public OutputStream getOutputStream(String path, boolean append);
192
193 /***
194 * Returns a <code>RandomAccess</code> interface implementation for accessing the file at
195 * arbitrary positions.
196 *
197 * @param path the abstract pathname.
198 * @param mode the string which defines the opening mode for this random access file,
199 * the form of this string is equal to the <code>mode</code> parameter in
200 * <code>java.io.RandomAccessFile</code> constructor.
201 * @return an RandomAccess interface implementation, or <code>null</code>
202 * if the operation is not supported.
203 */
204 public RandomAccessFile getRandomAccess(String path, String mode);
205
206 /***
207 * Returns an URL to the resource.
208 *
209 * @param path the abstract pathname.
210 * @return an URL to the resource, or null if not available.
211 * @throws MalformedURLException if the path contains invalid characters.
212 */
213 public URL getResource(String path) throws MalformedURLException;
214
215 /***
216 * Returns the time of the last modificaion of the specified file.
217 *
218 * <p>The time of the modification is returned as the number of
219 * milliseconds sice the epoch (Jan 1 1970), or -1L if the feature is not
220 * supported.</p>
221 *
222 * @param path the path.
223 * @return the time of last modification of the specified file.
224 */
225 public long lastModified(String path);
226
227 /***
228 * Returns the size of the specified file.
229 *
230 * @param path the path.
231 * @return the size of the file in bytes, of -1 if not supported.
232 */
233 public long length(String path);
234 }