156
169
//-----------------------------------------------------------------------
158
/* Constructed on demand and then cached */
159
private static IOFileFilter cvsFilter = null;
162
* Resturns an IOFileFilter that ignores CVS directories. You may optionally
163
* pass in an existing IOFileFilter in which case it is extended to exclude
165
* @param filter IOFileFilter to modify, null if a new IOFileFilter
167
* @return the requested (combined) filter
171
* Returns a filter that returns true if the file was last modified after
172
* the specified cutoff time.
174
* @param cutoff the time threshold
175
* @return an appropriately configured age file filter
176
* @since Commons IO 1.2
178
public static IOFileFilter ageFileFilter(long cutoff) {
179
return new AgeFileFilter(cutoff);
183
* Returns a filter that filters files based on a cutoff time.
185
* @param cutoff the time threshold
186
* @param acceptOlder if true, older files get accepted, if false, newer
187
* @return an appropriately configured age file filter
188
* @since Commons IO 1.2
190
public static IOFileFilter ageFileFilter(long cutoff, boolean acceptOlder) {
191
return new AgeFileFilter(cutoff, acceptOlder);
195
* Returns a filter that returns true if the file was last modified after
196
* the specified cutoff date.
198
* @param cutoffDate the time threshold
199
* @return an appropriately configured age file filter
200
* @since Commons IO 1.2
202
public static IOFileFilter ageFileFilter(Date cutoffDate) {
203
return new AgeFileFilter(cutoffDate);
207
* Returns a filter that filters files based on a cutoff date.
209
* @param cutoffDate the time threshold
210
* @param acceptOlder if true, older files get accepted, if false, newer
211
* @return an appropriately configured age file filter
212
* @since Commons IO 1.2
214
public static IOFileFilter ageFileFilter(Date cutoffDate, boolean acceptOlder) {
215
return new AgeFileFilter(cutoffDate, acceptOlder);
219
* Returns a filter that returns true if the file was last modified after
220
* the specified reference file.
222
* @param cutoffReference the file whose last modification
223
* time is usesd as the threshold age of the files
224
* @return an appropriately configured age file filter
225
* @since Commons IO 1.2
227
public static IOFileFilter ageFileFilter(File cutoffReference) {
228
return new AgeFileFilter(cutoffReference);
232
* Returns a filter that filters files based on a cutoff reference file.
234
* @param cutoffReference the file whose last modification
235
* time is usesd as the threshold age of the files
236
* @param acceptOlder if true, older files get accepted, if false, newer
237
* @return an appropriately configured age file filter
238
* @since Commons IO 1.2
240
public static IOFileFilter ageFileFilter(File cutoffReference, boolean acceptOlder) {
241
return new AgeFileFilter(cutoffReference, acceptOlder);
244
//-----------------------------------------------------------------------
246
* Returns a filter that returns true if the file is bigger than a certain size.
248
* @param threshold the file size threshold
249
* @return an appropriately configured SizeFileFilter
250
* @since Commons IO 1.2
252
public static IOFileFilter sizeFileFilter(long threshold) {
253
return new SizeFileFilter(threshold);
257
* Returns a filter that filters based on file size.
259
* @param threshold the file size threshold
260
* @param acceptLarger if true, larger files get accepted, if false, smaller
261
* @return an appropriately configured SizeFileFilter
262
* @since Commons IO 1.2
264
public static IOFileFilter sizeFileFilter(long threshold, boolean acceptLarger) {
265
return new SizeFileFilter(threshold, acceptLarger);
269
* Returns a filter that accepts files whose size is >= minimum size
270
* and <= maximum size.
272
* @param minSizeInclusive the minimum file size (inclusive)
273
* @param maxSizeInclusive the maximum file size (inclusive)
274
* @return an appropriately configured IOFileFilter
275
* @since Commons IO 1.3
277
public static IOFileFilter sizeRangeFileFilter(long minSizeInclusive, long maxSizeInclusive ) {
278
IOFileFilter minimumFilter = new SizeFileFilter(minSizeInclusive, true);
279
IOFileFilter maximumFilter = new SizeFileFilter(maxSizeInclusive + 1L, false);
280
return new AndFileFilter(minimumFilter, maximumFilter);
283
//-----------------------------------------------------------------------
284
/* Constructed on demand and then cached */
285
private static IOFileFilter cvsFilter;
287
/* Constructed on demand and then cached */
288
private static IOFileFilter svnFilter;
291
* Decorates a filter to make it ignore CVS directories.
292
* Passing in <code>null</code> will return a filter that accepts everything
293
* except CVS directories.
295
* @param filter the filter to decorate, null means an unrestricted filter
296
* @return the decorated filter, never null
297
* @since 1.1 (method existed but had bug in 1.0)
169
299
public static IOFileFilter makeCVSAware(IOFileFilter filter) {
170
300
if (cvsFilter == null) {
171
cvsFilter = andFileFilter(directoryFileFilter(),
172
notFileFilter(nameFileFilter("CVS")));
301
cvsFilter = notFileFilter(
302
andFileFilter(directoryFileFilter(), nameFileFilter("CVS")));
174
304
if (filter == null) {
175
305
return cvsFilter;
312
* Decorates a filter to make it ignore SVN directories.
313
* Passing in <code>null</code> will return a filter that accepts everything
314
* except SVN directories.
316
* @param filter the filter to decorate, null means an unrestricted filter
317
* @return the decorated filter, never null
320
public static IOFileFilter makeSVNAware(IOFileFilter filter) {
321
if (svnFilter == null) {
322
svnFilter = notFileFilter(
323
andFileFilter(directoryFileFilter(), nameFileFilter(".svn")));
325
if (filter == null) {
328
return andFileFilter(filter, svnFilter);
332
//-----------------------------------------------------------------------
334
* Decorates a filter so that it only applies to directories and not to files.
336
* @param filter the filter to decorate, null means an unrestricted filter
337
* @return the decorated filter, never null
340
public static IOFileFilter makeDirectoryOnly(IOFileFilter filter) {
341
if (filter == null) {
342
return DirectoryFileFilter.DIRECTORY;
344
return new AndFileFilter(DirectoryFileFilter.DIRECTORY, filter);
348
* Decorates a filter so that it only applies to files and not to directories.
350
* @param filter the filter to decorate, null means an unrestricted filter
351
* @return the decorated filter, never null
354
public static IOFileFilter makeFileOnly(IOFileFilter filter) {
355
if (filter == null) {
356
return FileFileFilter.FILE;
358
return new AndFileFilter(FileFileFilter.FILE, filter);