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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316 | package Torello.Java;
import static Torello.Java.C.*;
import java.util.*;
import Torello.JavaDoc.Annotations.LinkJavaSource;
import java.io.*;
import java.nio.file.*;
/**
* Operating-System independent utilities for moving, copying and deleting files, or an entire
* tree of files - using the <CODE>FileNode</CODE> class.
*
* <EMBED CLASS='external-html' DATA-FILE-ID=FILE_TRANSFER>
*/
@Torello.JavaDoc.Annotations.StaticFunctional
public class FileTransfer
{
private FileTransfer() { }
/**
* <EMBED CLASS='external-html' DATA-FILE-ID=FT_COPY_DESC>
* @param directory <EMBED CLASS='external-html' DATA-FILE-ID=FT_COPY_DIRECTORY>
* @param filter <EMBED CLASS='external-html' DATA-FILE-ID=FT_COPY_FILTER>
* @param targetDirectory <EMBED CLASS='external-html' DATA-FILE-ID=FT_COPY_TARGET_DIR>
*
* @param a This parameter may be null, but if it is not, then debugging / logging /
* informational messages will be sent to this output.
*
* <EMBED CLASS='external-html' DATA-FILE-ID=APPENDABLE>
*
* @return The number of files that were copied.
*
* @throws DirExpectedException If you pass a "file" instance of {@code class FileNode} to
* parameter {@code 'directory.'}
*
* @throws WritableDirectoryException If the target-directory is not available to Java for
* copying.
*
* @throws java.nio.file.NoSuchFileException This will be thrown if the logic which checks to
* ensure that the source and target directories are not identical is unable to identify the
* <I><B>real path name</B></I> of either the source or target directory. One such possible
* situation where this would happen would be if the user applied the UNIX <B>tilda
* ({@code '~'})</B> in either the {@code source} or {@code target} directory-name.
*
* @throws java.nio.file.InvalidPathException This will be thrown if {@code class
* java.nio.file.Paths} is unable to instantiate a {@code java.nio.file.Path} for either the
* source-directory (parameter {@code directory}), or the {@code targetDirectory}.
*
* @throws SameSourceAndTargetException This will be thrown if the source and target
* directories are found to point to identical locations on the file-system.
*
* @throws IOException For any IO filesystem errors.
*
* @see #copyRecursive(FileNode, FileNodeFilter, FileNodeFilter, String, Appendable)
* @see FileNode#getDirContentsFiles(RTC)
* @see DirExpectedException#check(FileNode)
* @see WritableDirectoryException#check(String)
* @see SameSourceAndTargetException#check(FileNode, String)
*/
@LinkJavaSource(handle="CopyFiles")
public static int copy(
final FileNode directory,
final FileNodeFilter filter,
final String targetDirectory,
final Appendable a
)
throws IOException, SameSourceAndTargetException,
InvalidPathException, NoSuchFileException
{
DirExpectedException.check(directory);
WritableDirectoryException.check(targetDirectory);
SameSourceAndTargetException.check(directory, targetDirectory);
final String td = targetDirectory.endsWith(File.separator)
? targetDirectory
: targetDirectory + File.separator;
return CopyFiles.COPY(directory, filter, td, a);
}
/**
* <EMBED CLASS='external-html' DATA-FILE-ID=FT_CPREC_DESC>
* @param directory <EMBED CLASS='external-html' DATA-FILE-ID=FT_CPREC_DIRECTORY>
* @param fileFilter <EMBED CLASS='external-html' DATA-FILE-ID=FT_CPREC_FILE_FILT>
* @param dirFilter <EMBED CLASS='external-html' DATA-FILE-ID=FT_CPREC_DIR_FILT>
* @param targetDirectory <EMBED CLASS='external-html' DATA-FILE-ID=FT_CPREC_TARGET_DIR>
*
* @param a This parameter may be null, but if it is not, then debugging / logging /
* informational messages will be sent to this output.
*
* @return This method makes calls to the single-level, single-directory-version of the
* {@code copy(...)} method in this class for each directory found in the tree. This method
* shall sum-up all and count all the files as they are copied. The value returned by this
* method is an integer specified how many files were copied in the process.
*
* @throws DirExpectedException If you pass a "file" instance of {@code class FileNode} to
* parameter {@code 'directory.'}
*
* @throws WritableDirectoryException If the initial target-directory, itself, is not available
* to Java for copying, then this exception shall throw. In actuality, all sub-directories
* that need to be created will be created by this recursive-copy operation - except for the
* highest-level "top directory" (the one indicated by the parameter {@code 'targetDirectory'}
* - because if that doesn't exist, then this {@code 'WritableDirectoryException'} will throw).
*
* @throws java.nio.file.NoSuchFileException This will be thrown if the logic which checks to
* ensure that the source and target directories are not identical is unable to identify the
* <I><B>real path name</B></I> of either the source or target directory. One such possible
* situation where this would happen would be if the user applied the UNIX <B>tilda
* ({@code '~'})</B> in either the {@code source} or {@code target} directory-name.
*
* @throws java.nio.file.InvalidPathException This will be thrown if {@code class
* java.nio.file.Paths} is unable to instantiate a {@code java.nio.file.Path} for either the
* source-directory (parameter {@code directory}), or the {@code targetDirectory}.
*
* @throws SameSourceAndTargetException This will be thrown if the source and target
* directories are found to point to identical locations on the file-system.
*
* @throws IOException For any IO filesystem errors.
*
* @see #copy(FileNode, FileNodeFilter, String, Appendable)
* @see FileNode#getDirContentsDirs(RTC)
* @see DirExpectedException#check(FileNode)
* @see WritableDirectoryException#check(String)
* @see SameSourceAndTargetException#check(FileNode, String)
*/
@LinkJavaSource(handle="CopyFiles")
public static int copyRecursive(
final FileNode directory,
final FileNodeFilter fileFilter,
final FileNodeFilter dirFilter,
final String targetDirectory,
final Appendable a
)
throws IOException, SameSourceAndTargetException,
InvalidPathException, NoSuchFileException
{
DirExpectedException.check(directory);
WritableDirectoryException.check(targetDirectory);
SameSourceAndTargetException.check(directory, targetDirectory);
final String td = targetDirectory.endsWith(File.separator)
? targetDirectory
: targetDirectory + File.separator;
return CopyFiles.RECURSIVE(directory, fileFilter, dirFilter, td, a);
}
/**
* <EMBED CLASS='external-html' DATA-FILE-ID=FT_DEL_DESC>
* @param directory <EMBED CLASS='external-html' DATA-FILE-ID=FT_DEL_DIRECTORY>
* @param filter <EMBED CLASS='external-html' DATA-FILE-ID=FT_DEL_FILTER>
* @param a An output log, for debugging & logging informational messages.
* This parameter may be null, and if so, it will be silently ignored.
* <EMBED CLASS='external-html' DATA-FILE-ID=APPENDABLE>
* @return <EMBED CLASS='external-html' DATA-FILE-ID=FT_DEL_RETURNS>
*
* @throws DirExpectedException If you pass a "file" instance of {@code class FileNode} to
* parameter {@code 'directory'}.
*
* @throws IOException For any IO file-system errors.
*
* @see #deleteFilesRecursive(FileNode, FileNodeFilter, FileNodeFilter, Appendable)
* @see FileNode#getDirContentsFiles(RTC)
* @see FileNode#getJavaIOFile()
* @see DirExpectedException#check(FileNode)
*/
@LinkJavaSource(handle="DeleteFiles")
public static int deleteFiles(
final FileNode directory,
final FileNodeFilter filter,
final Appendable a
)
throws IOException
{
DirExpectedException.check(directory);
return DeleteFiles.DELETE(directory, filter, a);
}
/**
* <EMBED CLASS='external-html' DATA-FILE-ID=FT_DELREC_DESC>
* @param directory <EMBED CLASS='external-html' DATA-FILE-ID=FT_DELREC_DIRECTORY>
* @param fileFilter <EMBED CLASS='external-html' DATA-FILE-ID=FT_DELREC_FILE_FILT>
* @param dirFilter <EMBED CLASS='external-html' DATA-FILE-ID=FT_DELREC_DIR_FILT>
* @param a An output log, for debugging & logging informational messages.
* This parameter may be null, and if so, it will be silently ignored.
* @return <EMBED CLASS='external-html' DATA-FILE-ID=FT_DELREC_RET>
*
* @throws DirExpectedException If you pass a "file" instance of {@code class FileNode} to
* parameter {@code 'directory'}
*
* @throws IOException For any IO file-system errors.
*
* @see #deleteFiles(FileNode, FileNodeFilter, Appendable)
* @see FileNode#getDirContentsDirs(RTC)
* @see FileNode#getJavaIOFile()
* @see DirExpectedException#check(FileNode)
*/
@LinkJavaSource(handle="DeleteFiles")
public static int deleteFilesRecursive(
FileNode directory, FileNodeFilter fileFilter, FileNodeFilter dirFilter,
Appendable a
)
throws IOException
{
DirExpectedException.check(directory);
return DeleteFiles.RECURSIVE(directory, fileFilter, dirFilter, a);
}
/**
* <EMBED CLASS='external-html' DATA-FILE-ID=FT_MV_DESC>
* @param directory <EMBED CLASS='external-html' DATA-FILE-ID=FT_MV_DIRECTORY>
* @param targetDirectory <EMBED CLASS='external-html' DATA-FILE-ID=FT_MV_TARGET_DIR>
* @param filter <EMBED CLASS='external-html' DATA-FILE-ID=FT_MV_FILTER>
* @param a An output log, for debugging & logging informational messages.
* This parameter may be null, and if so, it will be silently ignored.
* <EMBED CLASS='external-html' DATA-FILE-ID=APPENDABLE>
* @return The number of files that were moved.
*
* @throws DirExpectedException If you pass a "file" instance of {@code class FileNode} to
* parameter {@code 'directory.'}
*
* @throws WritableDirectoryException If the target-directory is not available to Java for
* moving.
*
* @throws java.nio.file.NoSuchFileException
* <EMBED CLASS='external-html' DATA-FILE-ID=FT_MV_NO_SUCH_F_EX>
*
* @throws java.nio.file.InvalidPathException
* <EMBED CLASS='external-html' DATA-FILE-ID=FT_MV_INVALID_P_EX>
*
* @throws SameSourceAndTargetException
* <EMBED CLASS='external-html' DATA-FILE-ID=FT_MV_SAME_SRC_T_EX>
*
* @throws IOException For any IO file-system errors.
*
* @see #moveRecursive(FileNode, FileNodeFilter, FileNodeFilter, String, Appendable)
* @see DirExpectedException#check(FileNode)
* @see WritableDirectoryException#check(String)
* @see SameSourceAndTargetException#check(FileNode, String)
*/
@LinkJavaSource(handle="MoveFiles")
public static int move(
final FileNode directory,
final FileNodeFilter filter,
final String targetDirectory,
final Appendable a
)
throws IOException, SameSourceAndTargetException,
InvalidPathException, NoSuchFileException
{
DirExpectedException.check(directory);
WritableDirectoryException.check(targetDirectory);
SameSourceAndTargetException.check(directory, targetDirectory);
final String td = targetDirectory.endsWith(File.separator)
? targetDirectory
: targetDirectory + File.separator;
return MoveFiles.MOVE(directory, filter, td, a);
}
/**
* <EMBED CLASS='external-html' DATA-FILE-ID=FT_MVREC_DESC>
* @param directory <EMBED CLASS='external-html' DATA-FILE-ID=FT_MVREC_DIRECTORY>
* @param targetDirectory <EMBED CLASS='external-html' DATA-FILE-ID=FT_MVREC_TARGET_DIR>
* @param fileFilter <EMBED CLASS='external-html' DATA-FILE-ID=FT_MVREC_DIR_FILT>
* @param dirFilter <EMBED CLASS='external-html' DATA-FILE-ID=FT_MVREC_FILE_FILT>
* @param a An output log, for debugging & logging informational messages.
* This parameter may be null, and if so, it will be silently ignored.
* @return <EMBED CLASS='external-html' DATA-FILE-ID=FT_MVREC_RET>
*
* @throws DirExpectedException If you pass a "file" instance of {@code class FileNode} to
* parameter {@code 'directory.'}
*
* @throws WritableDirectoryException
* <EMBED CLASS='external-html' DATA-FILE-ID=FT_MVREC_W_DIR_EX>
*
* @throws java.nio.file.NoSuchFileException
* <EMBED CLASS='external-html' DATA-FILE-ID=FT_MV_NO_SUCH_F_EX>
*
* @throws java.nio.file.InvalidPathException
* <EMBED CLASS='external-html' DATA-FILE-ID=FT_MV_INVALID_P_EX>
*
* @throws SameSourceAndTargetException
* <EMBED CLASS='external-html' DATA-FILE-ID=FT_MV_SAME_SRC_T_EX>
*
* @throws IOException For any IO filesystem errors.
*
* @see #move(FileNode, FileNodeFilter, String, Appendable)
* @see FileNode#getDirContentsDirs(RTC)
* @see DirExpectedException#check(FileNode)
* @see WritableDirectoryException#check(String)
* @see SameSourceAndTargetException#check(FileNode, String)
*/
@LinkJavaSource(handle="MoveFiles")
public static int moveRecursive(
FileNode directory, FileNodeFilter fileFilter, FileNodeFilter dirFilter,
String targetDirectory, Appendable a
)
throws IOException, SameSourceAndTargetException,
InvalidPathException, NoSuchFileException
{
DirExpectedException.check(directory);
WritableDirectoryException.check(targetDirectory);
SameSourceAndTargetException.check(directory, targetDirectory);
final String td = targetDirectory.endsWith(File.separator)
? targetDirectory
: targetDirectory + File.separator;
return MoveFiles.RECURSIVE(directory, fileFilter, dirFilter, td, a);
}
}
|