下面列出了org.apache.commons.io.filefilter.FileFilterUtils#makeDirectoryOnly ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void run() {
try {
if (!shutdown.get()) {
LOGGER.info("Actively cleaning up directories older than " + TimeUnit.MILLISECONDS.toHours(cleanupAgeMillis) + " hours");
final IOFileFilter olderThanFilter = FileFilterUtils.asFileFilter(olderThanFileFilter(cleanupAgeMillis));
final IOFileFilter tempDirFilter =
FileFilterUtils.prefixFileFilter(prefix);
/*
* Delete directories that are:
* older than [clean up age millis]
* starts with temp-dir-prefix
*/
final IOFileFilter deleteAfterMillisFilter = FileFilterUtils.makeDirectoryOnly(
FileFilterUtils.andFileFilter(olderThanFilter, tempDirFilter)
);
deleteUserDirectories(rootDirectory, deleteAfterMillisFilter);
} else {
LOGGER.info("Currently shutdown, skipping older-than directory cleanup");
}
} catch (Exception e) {
LOGGER.error("Unhandled Exception during directory cleanup", e);
}
}
/**
* Construct an instance with a directory and a file filter and an optional
* limit on the <i>depth</i> navigated to.
* <p>
* The filters control which files and directories will be navigated to as part
* of the walk. This constructor uses {@link FileFilterUtils#makeDirectoryOnly(IOFileFilter)}
* and {@link FileFilterUtils#makeFileOnly(IOFileFilter)} internally to combine the filters.
* A {@code null} filter means that no filtering should occur.
*
* @param directoryFilter the filter to apply to directories, null means visit all directories
* @param fileFilter the filter to apply to files, null means visit all files
* @param depthLimit controls how <i>deep</i> the hierarchy is
* navigated to (less than 0 means unlimited)
*/
protected DirectoryWalker(IOFileFilter directoryFilter, IOFileFilter fileFilter, int depthLimit) {
if (directoryFilter == null && fileFilter == null) {
this.filter = null;
} else {
directoryFilter = directoryFilter != null ? directoryFilter : TrueFileFilter.TRUE;
fileFilter = fileFilter != null ? fileFilter : TrueFileFilter.TRUE;
directoryFilter = FileFilterUtils.makeDirectoryOnly(directoryFilter);
fileFilter = FileFilterUtils.makeFileOnly(fileFilter);
this.filter = FileFilterUtils.or(directoryFilter, fileFilter);
}
this.depthLimit = depthLimit;
}
/**
* Construct an instance with a directory and a file filter and an optional
* limit on the <i>depth</i> navigated to.
* <p>
* The filters control which files and directories will be navigated to as part
* of the walk. This constructor uses {@link FileFilterUtils#makeDirectoryOnly(IOFileFilter)}
* and {@link FileFilterUtils#makeFileOnly(IOFileFilter)} internally to combine the filters.
* A {@code null} filter means that no filtering should occur.
*
* @param directoryFilter the filter to apply to directories, null means visit all directories
* @param fileFilter the filter to apply to files, null means visit all files
* @param depthLimit controls how <i>deep</i> the hierarchy is
* navigated to (less than 0 means unlimited)
*/
protected DirectoryWalker(IOFileFilter directoryFilter, IOFileFilter fileFilter, final int depthLimit) {
if (directoryFilter == null && fileFilter == null) {
this.filter = null;
} else {
directoryFilter = directoryFilter != null ? directoryFilter : TrueFileFilter.TRUE;
fileFilter = fileFilter != null ? fileFilter : TrueFileFilter.TRUE;
directoryFilter = FileFilterUtils.makeDirectoryOnly(directoryFilter);
fileFilter = FileFilterUtils.makeFileOnly(fileFilter);
this.filter = FileFilterUtils.or(directoryFilter, fileFilter);
}
this.depthLimit = depthLimit;
}