[1cff17]: src / org / esb / io / File.h  Maximize  Restore  History

Download this file

294 lines (274 with data), 12.6 kB

  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
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
#ifndef ORG_ESB_IO_FILE_H
#define ORG_ESB_IO_FILE_H
#include <list>
#include <boost/shared_ptr.hpp>
#include <boost/filesystem/path.hpp>
#include "org/esb/util/Log.h"
#include "FileFilter.h"
namespace org {
namespace esb {
namespace io {
typedef std::list<boost::shared_ptr<File> > FileList;
class File {
public:
/**
* Creates a new <code>File</code> instance by converting the given
* pathname string into an abstract pathname. If the given string is
* the empty string, then the result is the empty abstract pathname.
*
* @param pathname A pathname string
* @throws NullPointerException
* If the <code>pathname</code> argument is <code>null</code>
*/
File(const char * filename);
~File();
/**
* Converts this abstract pathname into a pathname string. The resulting
* string uses the {@link #separator default name-separator character} to
* separate the names in the name sequence.
*
* @return The string form of this abstract pathname
*/
const std::string getPath();
const std::string getFileName();
const std::string getFilePath();
/**
* Tests whether the application can read the file denoted by this
* abstract pathname.
*
* @return <code>true</code> if and only if the file specified by this
* abstract pathname exists <em>and</em> can be read by the
* application; <code>false</code> otherwise
*
* @throws SecurityException
* If a security manager exists and its <code>{@link
* java.lang.SecurityManager#checkRead(java.lang.String)}</code>
* method denies read access to the file
*/
bool canRead();
/**
* Tests whether the application can modify the file denoted by this
* abstract pathname.
*
* @return <code>true</code> if and only if the file system actually
* contains a file denoted by this abstract pathname <em>and</em>
* the application is allowed to write to the file;
* <code>false</code> otherwise.
*
* @throws SecurityException
* If a security manager exists and its <code>{@link
* java.lang.SecurityManager#checkWrite(java.lang.String)}</code>
* method denies write access to the file
*/
bool canWrite();
/**
* Tests whether the file or directory denoted by this abstract pathname
* exists.
*
* @return <code>true</code> if and only if the file or directory denoted
* by this abstract pathname exists; <code>false</code> otherwise
*
* @throws SecurityException
* If a security manager exists and its <code>{@link
* java.lang.SecurityManager#checkRead(java.lang.String)}</code>
* method denies read access to the file or directory
*/
bool exists();
/**
* Tests whether the file denoted by this abstract pathname is a normal
* file. A file is <em>normal</em> if it is not a directory and, in
* addition, satisfies other system-dependent criteria. Any non-directory
* file created by an application is guaranteed to be a normal file.
*
* @return <code>true</code> if and only if the file denoted by this
* abstract pathname exists <em>and</em> is a normal file;
* <code>false</code> otherwise
*
* @throws SecurityException
* If a security manager exists and its <code>{@link
* java.lang.SecurityManager#checkRead(java.lang.String)}</code>
* method denies read access to the file
*/
bool isFile();
/**
* Tests whether the file denoted by this abstract pathname is a
* directory.
*
* @return <code>true</code> if and only if the file denoted by this
* abstract pathname exists <em>and</em> is a directory;
* <code>false</code> otherwise
*
* @throws SecurityException
* If a security manager exists and its <code>{@link
* java.lang.SecurityManager#checkRead(java.lang.String)}</code>
* method denies read access to the file
*/
bool isDirectory();
/**
* Atomically creates a new, empty file named by this abstract pathname if
* and only if a file with this name does not yet exist. The check for the
* existence of the file and the creation of the file if it does not exist
* are a single operation that is atomic with respect to all other
* filesystem activities that might affect the file.
* <P>
* Note: this method should <i>not</i> be used for file-locking, as
* the resulting protocol cannot be made to work reliably. The
* {@link java.nio.channels.FileLock FileLock}
* facility should be used instead.
*
* @return <code>true</code> if the named file does not exist and was
* successfully created; <code>false</code> if the named file
* already exists
*
* @throws IOException
* If an I/O error occurred
*
* @throws SecurityException
* If a security manager exists and its <code>{@link
* java.lang.SecurityManager#checkWrite(java.lang.String)}</code>
* method denies write access to the file
*
* @since 1.2
*/
bool createNewFile();
/**
* Deletes the file or directory denoted by this abstract pathname. If
* this pathname denotes a directory, then the directory must be empty in
* order to be deleted.
*
* @return <code>true</code> if and only if the file or directory is
* successfully deleted; <code>false</code> otherwise
*
* @throws SecurityException
* If a security manager exists and its <code>{@link
* java.lang.SecurityManager#checkDelete}</code> method denies
* delete access to the file
*/
bool deleteFile();
/**
* Returns the length of the file denoted by this abstract pathname.
* The return value is unspecified if this pathname denotes a directory.
*
* @return The length, in bytes, of the file denoted by this abstract
* pathname, or <code>0L</code> if the file does not exist
*
* @throws SecurityException
* If a security manager exists and its <code>{@link
* java.lang.SecurityManager#checkRead(java.lang.String)}</code>
* method denies read access to the file
*/
long length();
/**
* Creates the directory named by this abstract pathname.
*
* @return <code>true</code> if and only if the directory was
* created; <code>false</code> otherwise
*
* @throws SecurityException
* If a security manager exists and its <code>{@link
* java.lang.SecurityManager#checkWrite(java.lang.String)}</code>
* method does not permit the named directory to be created
*/
bool mkdir();
/**
* Creates the directory named by this abstract pathname, including any
* necessary but nonexistent parent directories. Note that if this
* operation fails it may have succeeded in creating some of the necessary
* parent directories.
*
* @return <code>true</code> if and only if the directory was created,
* along with all necessary parent directories; <code>false</code>
* otherwise
*
* @throws SecurityException
* If a security manager exists and its <code>{@link
* java.lang.SecurityManager#checkRead(java.lang.String)}</code>
* method does not permit verification of the existence of the
* named directory and all necessary parent directories; or if
* the <code>{@link
* java.lang.SecurityManager#checkWrite(java.lang.String)}</code>
* method does not permit the named directory and all necessary
* parent directories to be created
*/
bool mkdirs();
/**
* Renames the file denoted by this abstract pathname.
*
* <p> Many aspects of the behavior of this method are inherently
* platform-dependent: The rename operation might not be able to move a
* file from one filesystem to another, it might not be atomic, and it
* might not succeed if a file with the destination abstract pathname
* already exists. The return value should always be checked to make sure
* that the rename operation was successful.
*
* @param dest The new abstract pathname for the named file
*
* @return <code>true</code> if and only if the renaming succeeded;
* <code>false</code> otherwise
*
* @throws SecurityException
* If a security manager exists and its <code>{@link
* java.lang.SecurityManager#checkWrite(java.lang.String)}</code>
* method denies write access to either the old or new pathnames
*
* @throws NullPointerException
* If parameter <code>dest</code> is <code>null</code>
*/
bool renameTo(File * dest);
/**
* Sets the last-modified time of the file or directory named by this
* abstract pathname.
*
* <p> All platforms support file-modification times to the nearest second,
* but some provide more precision. The argument will be truncated to fit
* the supported precision. If the operation succeeds and no intervening
* operations on the file take place, then the next invocation of the
* <code>{@link #lastModified}</code> method will return the (possibly
* truncated) <code>time</code> argument that was passed to this method.
*
* @param time The new last-modified time, measured in milliseconds since
* the epoch (00:00:00 GMT, January 1, 1970)
*
* @return <code>true</code> if and only if the operation succeeded;
* <code>false</code> otherwise
*
* @throws IllegalArgumentException If the argument is negative
*
* @throws SecurityException
* If a security manager exists and its <code>{@link
* java.lang.SecurityManager#checkWrite(java.lang.String)}</code>
* method denies write access to the named file
*
* @since 1.2
*/
bool setLastModified(long date);
long getLastModified();
/**
* Marks the file or directory named by this abstract pathname so that
* only read operations are allowed. After invoking this method the file
* or directory is guaranteed not to change until it is either deleted or
* marked to allow write access. Whether or not a read-only file or
* directory may be deleted depends upon the underlying system.
*
* @return <code>true</code> if and only if the operation succeeded;
* <code>false</code> otherwise
*
* @throws SecurityException
* If a security manager exists and its <code>{@link
* java.lang.SecurityManager#checkWrite(java.lang.String)}</code>
* method denies write access to the named file
*
* @since 1.2
*/
bool setReadOnly();
FileList listFiles();
FileList listFiles(FileFilter & filter);
private:
// const char * _filename;
boost::filesystem::path _full_path;
logger("io.file");
};
}
}
}
#endif