1 /**
2 This file is part of GoldenGate Project (named also GoldenGate or GG).
3
4 Copyright 2009, Frederic Bregier, and individual contributors by the @author
5 tags. See the COPYRIGHT.txt in the distribution for a full listing of
6 individual contributors.
7
8 All GoldenGate Project is free software: you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as published
10 by the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 GoldenGate is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GoldenGate . If not, see <http://www.gnu.org/licenses/>.
20 */
21 package goldengate.common.file;
22
23 import goldengate.common.command.exception.CommandAbstractException;
24 import goldengate.common.command.exception.Reply530Exception;
25
26 import java.util.List;
27
28 /**
29 * Interface for Directory support
30 *
31 * @author Frederic Bregier
32 *
33 */
34 public interface DirInterface {
35 /**
36 * FileInterface separator for external
37 */
38 public static final String SEPARATOR = "/";
39
40 /**
41 * FileInterface separator for external
42 */
43 public static final char SEPARATORCHAR = '/';
44
45 /**
46 *
47 * @return the current value of Options for MLSx
48 */
49 public OptsMLSxInterface getOptsMLSx();
50
51 /**
52 * Set empty this FtpDir, mark it unReady.
53 */
54 public void clear();
55
56 /**
57 * Init DirInterface after authentication is done
58 *
59 */
60 public void initAfterIdentification();
61
62 /**
63 * Check if the authentication is correct
64 *
65 * @throws Reply530Exception
66 */
67 public void checkIdentify() throws Reply530Exception;
68
69 /**
70 *
71 * @return the FtpSession
72 */
73 public SessionInterface getSession();
74
75 // **************** Directory part **************************
76 /**
77 * Construct and Check if the given path is valid from business point of
78 * view (see {@link AuthInterface})
79 *
80 * @param path
81 * @return the construct and validated path (could be different than the one
82 * given as argument, example: '..' are removed)
83 * @throws CommandAbstractException
84 */
85 public abstract String validatePath(String path)
86 throws CommandAbstractException;
87
88 /**
89 * @return the current PWD
90 * @exception CommandAbstractException
91 */
92 public abstract String getPwd() throws CommandAbstractException;
93
94 /**
95 * Change directory with the one given as argument
96 *
97 * @param path
98 * @return True if the change is valid
99 * @throws CommandAbstractException
100 */
101 public abstract boolean changeDirectory(String path)
102 throws CommandAbstractException;
103
104 /**
105 * Change directory with the one given as argument without checking existence
106 *
107 * @param path
108 * @return True if the change is valid
109 * @throws CommandAbstractException
110 */
111 public abstract boolean changeDirectoryNotChecked(String path)
112 throws CommandAbstractException;
113
114 /**
115 * Change for parent directory
116 *
117 * @return True if the change is valid
118 * @throws CommandAbstractException
119 */
120 public abstract boolean changeParentDirectory()
121 throws CommandAbstractException;
122
123 /**
124 * Create the directory associated with the String as path
125 *
126 * @param directory
127 * @return the full path of the new created directory
128 * @exception CommandAbstractException
129 */
130 public abstract String mkdir(String directory)
131 throws CommandAbstractException;
132
133 /**
134 * Delete the directory associated with the String as path
135 *
136 * @param directory
137 * @return the full path of the new deleted directory
138 * @exception CommandAbstractException
139 */
140 public abstract String rmdir(String directory)
141 throws CommandAbstractException;
142
143 /**
144 * Is the given path a directory and exists
145 *
146 * @param path
147 * @return True if it is a directory and it exists
148 * @throws CommandAbstractException
149 */
150 public abstract boolean isDirectory(String path)
151 throws CommandAbstractException;
152
153 /**
154 * Is the given path a file and exists
155 *
156 * @param path
157 * @return True if it is a file and it exists
158 * @throws CommandAbstractException
159 */
160 public abstract boolean isFile(String path) throws CommandAbstractException;
161
162 /**
163 * Return the Modification time for the path
164 *
165 * @param path
166 * @return the Modification time as a String YYYYMMDDHHMMSS.sss
167 * @throws CommandAbstractException
168 */
169 public abstract String getModificationTime(String path)
170 throws CommandAbstractException;
171
172 /**
173 * List all files from the given path (could be a file or a directory)
174 *
175 * @param path
176 * @return the list of paths
177 * @throws CommandAbstractException
178 */
179 public abstract List<String> list(String path)
180 throws CommandAbstractException;
181
182 /**
183 * List all files with other informations from the given path (could be a
184 * file or a directory)
185 *
186 * @param path
187 * @param lsFormat
188 * True if ls Format, else MLSx format
189 * @return the list of paths and other informations
190 * @throws CommandAbstractException
191 */
192 public abstract List<String> listFull(String path, boolean lsFormat)
193 throws CommandAbstractException;
194
195 /**
196 * Give for 1 file all informations from the given path (could be a file or
197 * a directory)
198 *
199 * @param path
200 * @param lsFormat
201 * True if ls Format, else MLSx format
202 * @return the path and other informations
203 * @throws CommandAbstractException
204 */
205 public abstract String fileFull(String path, boolean lsFormat)
206 throws CommandAbstractException;
207
208 /**
209 *
210 * @return the free space of the current Directory
211 * @throws CommandAbstractException
212 */
213 public abstract long getFreeSpace() throws CommandAbstractException;
214
215 // **************** Unique FileInterface part **************************
216 /**
217 * Create a new File
218 *
219 * @param path
220 * @param append
221 * @return the new FileInterface
222 * @throws CommandAbstractException
223 */
224 public abstract FileInterface newFile(String path, boolean append)
225 throws CommandAbstractException;
226
227 /**
228 * Set a path as the current FileInterface
229 *
230 * @param path
231 * @param append
232 * True if this file is supposed to be in append mode (APPE),
233 * False in any other cases
234 * @return the FileInterface if it is correctly initiate
235 * @throws CommandAbstractException
236 */
237 public abstract FileInterface setFile(String path, boolean append)
238 throws CommandAbstractException;
239
240 /**
241 * Set a new unique path as the current FileInterface from the current
242 * Directory (STOU)
243 *
244 * @return the FileInterface if it is correctly initiate
245 * @throws CommandAbstractException
246 */
247 public abstract FileInterface setUniqueFile()
248 throws CommandAbstractException;
249
250 /**
251 * @return True if the current FileInterface is ready for reading
252 * @throws CommandAbstractException
253 */
254 public abstract boolean canRead() throws CommandAbstractException;
255
256 /**
257 *
258 * @return True if the current FileInterface is ready for writing
259 * @throws CommandAbstractException
260 */
261 public abstract boolean canWrite() throws CommandAbstractException;
262
263 /**
264 *
265 * @return True if the current FileInterface exists
266 * @throws CommandAbstractException
267 */
268 public abstract boolean exists() throws CommandAbstractException;
269
270 /**
271 * Get the CRC of the given FileInterface
272 *
273 * @param path
274 * @return the CRC
275 * @throws CommandAbstractException
276 */
277 public abstract long getCRC(String path) throws CommandAbstractException;
278
279 /**
280 * Get the MD5 of the given FileInterface
281 *
282 * @param path
283 * @return the MD5
284 * @throws CommandAbstractException
285 */
286 public abstract byte[] getMD5(String path) throws CommandAbstractException;
287
288 /**
289 * Get the SHA-1 of the given FileInterface
290 *
291 * @param path
292 * @return the SHA-1
293 * @throws CommandAbstractException
294 */
295 public abstract byte[] getSHA1(String path) throws CommandAbstractException;
296 }