1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package org.apache.commons.vfs2;
18
19 import java.io.File;
20
21 /**
22 * A file system, made up of a hierarchy of files.
23 */
24 public interface FileSystem {
25
26 /**
27 * Adds a junction to this file system. A junction is a link that attaches the supplied file to a point in this file
28 * system, making it look like part of the file system.
29 *
30 * @param junctionPoint The point in this file system to add the junction.
31 * @param targetFile The file to link to.
32 * @throws FileSystemException If this file system does not support junctions, or the junction point or target file
33 * is invalid (the file system may not support nested junctions, for example).
34 */
35 void addJunction(String junctionPoint, FileObject targetFile) throws FileSystemException;
36
37 /**
38 * Adds a listener on a file in this file system.
39 *
40 * @param file The file to attach the listener to.
41 * @param listener The listener to add.
42 */
43 void addListener(FileObject file, FileListener listener);
44
45 /**
46 * Gets the value of an attribute of the file system.
47 * <p>
48 * TODO - change to {@code Map getAttributes()} instead?
49 * </p>
50 * <p>
51 * TODO - define the standard attribute names, and define which attrs are guaranteed to be present.
52 * </p>
53 *
54 * @param attrName The name of the attribute.
55 * @return The value of the attribute.
56 * @throws org.apache.commons.vfs2.FileSystemException If the file does not exist, or is being written, or if the
57 * attribute is unknown.
58 * @see org.apache.commons.vfs2.FileContent#getAttribute
59 */
60 Object getAttribute(String attrName) throws FileSystemException;
61
62 /**
63 * Returns a reference to the FileSystemManager.
64 *
65 * @return The FileSystemManager.
66 */
67 FileSystemManager getFileSystemManager();
68
69 /**
70 * Returns the FileSystemOptions used to instantiate this file system.
71 *
72 * @return The FileSystemOptions.
73 */
74 FileSystemOptions getFileSystemOptions();
75
76 /**
77 * Returns the accuracy of the last modification time in milliseconds.
78 * <p>
79 * The local file provider is not very smart in figuring this out, for remote access to file systems the providers
80 * typically don't know the value of the underlying real file system.
81 * </p>
82 *
83 * @return the accuracy of the last modification time in milliseconds. A value of 0 means perfectly accurate,
84 * anything {@literal > 0} might be off by this value. For example, sftp has an accuracy of 1000
85 * milliseconds.
86 */
87 double getLastModTimeAccuracy();
88
89 /**
90 * Returns the parent layer if this is a layered file system.
91 *
92 * @return The parent layer, or null if this is not a layered file system.
93 * @throws FileSystemException if an error occurs.
94 */
95 FileObject getParentLayer() throws FileSystemException;
96
97 /**
98 * Returns the root file of this file system.
99 *
100 * @return The root FileObject.
101 * @throws FileSystemException if an error occurs.
102 */
103 FileObject getRoot() throws FileSystemException;
104
105 /**
106 * Returns the name of the root file of this file system. The root name always contains a path String of "/".
107 *
108 * @return the root FileName.
109 */
110 FileName getRootName();
111
112 /**
113 * The root URI passed as a file system option or obtained from the rootName.
114 *
115 * @return The root URI.
116 */
117 String getRootURI();
118
119 /**
120 * Determines if this file system has a particular capability.
121 * <p>
122 * TODO - Move this to another interface, so that set of capabilities can be queried.
123 * </p>
124 *
125 * @param capability The capability to check for.
126 * @return true if this file system has the requested capability. Note that not all files in the file system may have
127 * the capability.
128 */
129 boolean hasCapability(Capability capability);
130
131 /**
132 * Removes a junction from this file system.
133 *
134 * @param junctionPoint The junction to remove.
135 * @throws FileSystemException On error removing the junction.
136 */
137 void removeJunction(String junctionPoint) throws FileSystemException;
138
139 /**
140 * Removes a listener from a file in this file system.
141 *
142 * @param file The file to remove the listener from.
143 * @param listener The listener to remove.
144 */
145 void removeListener(FileObject file, FileListener listener);
146
147 /**
148 * Creates a temporary local copy of a file and its descendants. If this file is already a local file, a copy is not
149 * made.
150 * <p>
151 * Note that the local copy may include additional files, that were not selected by the given selector.
152 * </p>
153 * <p>
154 * TODO - Add options to indicate whether the caller is happy to deal with extra files being present locally (eg if
155 * the file has been replicated previously), or whether the caller expects only the selected files to be present.
156 * </p>
157 *
158 * @param file The file to replicate.
159 * @param selector The selector to use to select the files to replicate.
160 * @return The local copy of this file.
161 * @throws FileSystemException If this file does not exist, or on error replicating the file.
162 */
163 File replicateFile(FileObject file, FileSelector selector) throws FileSystemException;
164
165 /**
166 * Finds a file in this file system.
167 *
168 * @param name The name of the file.
169 * @return The file. Never returns null.
170 * @throws FileSystemException if an error occurs.
171 */
172 FileObject resolveFile(FileName name) throws FileSystemException;
173
174 /**
175 * Finds a file in this file system.
176 *
177 * @param name The name of the file. This must be an absolute path.
178 * @return The file. Never returns null.
179 * @throws FileSystemException if an error occurs.
180 */
181 FileObject resolveFile(String name) throws FileSystemException;
182
183 /**
184 * Sets the value of an attribute of the file's content. Creates the file if it does not exist.
185 *
186 * @param attrName The name of the attribute.
187 * @param value The value of the attribute.
188 * @throws FileSystemException If the file is read-only, or is being read, or if the attribute is not supported, or
189 * on error setting the attribute.
190 * @see FileContent#setAttribute
191 */
192 void setAttribute(String attrName, Object value) throws FileSystemException;
193 }