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 import goldengate.common.exception.FileEndOfTransferException;
26 import goldengate.common.exception.FileTransferException;
27
28 /**
29 * Interface for File support
30 *
31 * @author Frederic Bregier
32 *
33 */
34 public interface FileInterface {
35 /**
36 * Set empty this FtpFile, mark it unReady.
37 *
38 * @throws CommandAbstractException
39 */
40 public void clear() throws CommandAbstractException;
41
42 /**
43 * Check if the authentication is correct
44 *
45 * @throws Reply530Exception
46 */
47 public void checkIdentify() throws Reply530Exception;
48
49 /**
50 *
51 * @return the FtpSession
52 */
53 public SessionInterface getSession();
54
55 // **************** Directory part **************************
56 /**
57 *
58 * @return the FtpDir associated at creation with this file
59 */
60 public DirInterface getDir();
61
62 /**
63 * Is the current FileInterface a directory and exists
64 *
65 * @return True if it is a directory and it exists
66 * @throws CommandAbstractException
67 */
68 public abstract boolean isDirectory() throws CommandAbstractException;
69
70 /**
71 * Is the current FileInterface a file and exists
72 *
73 * @return True if it is a file and it exists
74 * @throws CommandAbstractException
75 */
76 public abstract boolean isFile() throws CommandAbstractException;
77
78 // **************** Unique FileInterface part **************************
79 /**
80 *
81 * @return the path of the current FileInterface (without mount point if
82 * any)
83 * @throws CommandAbstractException
84 */
85 public abstract String getFile() throws CommandAbstractException;
86
87 /**
88 * Close the current FileInterface
89 *
90 * @return True if correctly closed
91 * @throws CommandAbstractException
92 */
93 public abstract boolean closeFile() throws CommandAbstractException;
94
95 /**
96 *
97 * @return the length of the current FileInterface
98 * @throws CommandAbstractException
99 */
100 public abstract long length() throws CommandAbstractException;
101
102 /**
103 * @return True if the current FileInterface is in Writing process
104 * @throws CommandAbstractException
105 */
106 public abstract boolean isInWriting() throws CommandAbstractException;
107
108 /**
109 *
110 * @return True if the current FileInterface is in Reading process
111 * @throws CommandAbstractException
112 */
113 public abstract boolean isInReading() throws CommandAbstractException;
114
115 /**
116 * @return True if the current FileInterface is ready for reading
117 * @throws CommandAbstractException
118 */
119 public abstract boolean canRead() throws CommandAbstractException;
120
121 /**
122 *
123 * @return True if the current FileInterface is ready for writing
124 * @throws CommandAbstractException
125 */
126 public abstract boolean canWrite() throws CommandAbstractException;
127
128 /**
129 *
130 * @return True if the current FileInterface exists
131 * @throws CommandAbstractException
132 */
133 public abstract boolean exists() throws CommandAbstractException;
134
135 /**
136 * Try to abort the current transfer if any
137 *
138 * @return True if everything is ok
139 * @throws CommandAbstractException
140 */
141 public abstract boolean abortFile() throws CommandAbstractException;
142
143 /**
144 * Ask to store the current FileInterface. This command returns quickly
145 * since it does not store really. It prepares the object.
146 *
147 * @return True if everything is ready
148 * @throws CommandAbstractException
149 */
150 public abstract boolean store() throws CommandAbstractException;
151
152 /**
153 * Ask to retrieve the current FileInterface. This command returns quickly
154 * since it does not retrieve really. It prepares the object.
155 *
156 * @return True if everything is ready
157 * @throws CommandAbstractException
158 */
159 public abstract boolean retrieve() throws CommandAbstractException;
160
161 /**
162 * Rename the current FileInterface into a new filename from argument
163 *
164 * @param path
165 * the new filename (path could be relative or absolute - without
166 * mount point)
167 * @return True if the operation is done successfully
168 * @throws CommandAbstractException
169 */
170 public abstract boolean renameTo(String path)
171 throws CommandAbstractException;
172
173 /**
174 * Restart from a Marker for the current FileInterface if any. This function
175 * is to be called at the beginning of every transfer so in store and
176 * retrieve method.
177 *
178 * @param restart
179 * @return True if the Marker is OK
180 * @exception CommandAbstractException
181 */
182 public abstract boolean restartMarker(Restart restart)
183 throws CommandAbstractException;
184
185 /**
186 * Create a restart from context for the current FileInterface
187 *
188 * @return the dataBlock to send to the client
189 * @exception CommandAbstractException
190 */
191 public abstract DataBlock getMarker() throws CommandAbstractException;
192
193 /**
194 * Delete the current FileInterface.
195 *
196 * @return True if OK, else False if not (or if the file never exists).
197 * @exception CommandAbstractException
198 */
199 public abstract boolean delete() throws CommandAbstractException;
200
201 /**
202 * Function called by the DataNetworkHandler when it receives one DataBlock
203 * (Store like command)
204 *
205 * @param dataBlock
206 * @throws FileTransferException
207 * @throws FileEndOfTransferException
208 */
209 public void writeDataBlock(DataBlock dataBlock)
210 throws FileTransferException;
211
212 /**
213 * Read a new block for FileInterface
214 *
215 * @return dataBlock
216 * @throws FileEndOfTransferException
217 * @throws FileTransferException
218 */
219 public DataBlock readDataBlock() throws FileEndOfTransferException,
220 FileTransferException;
221 }