本文整理汇总了Java中org.apache.commons.io.filefilter.AgeFileFilter类的典型用法代码示例。如果您正苦于以下问题:Java AgeFileFilter类的具体用法?Java AgeFileFilter怎么用?Java AgeFileFilter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AgeFileFilter类属于org.apache.commons.io.filefilter包,在下文中一共展示了AgeFileFilter类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: initQueueDir
import org.apache.commons.io.filefilter.AgeFileFilter; //导入依赖的package包/类
private void initQueueDir() {
queueDir = new File(homeDir, "queue");
queueCleanupScheduler = Executors.newScheduledThreadPool(1);
queueCleanupScheduler.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
if (!queueDir.isDirectory())
return;
long cutoff = System.currentTimeMillis() - (10 * 60 * 1000); // 10 minutes old
File[] oldFiles = queueDir.listFiles((FileFilter) new AgeFileFilter(cutoff));
for (File file : oldFiles) {
if (!FileUtils.deleteQuietly(file))
logger.error("Could not delete stale file \"" + file.getAbsolutePath() + "\" in queue folder");
}
}
}, 10, 10, TimeUnit.MINUTES);
}
开发者ID:Armatiek,项目名称:xslweb,代码行数:18,代码来源:Context.java
示例2: deleteBackupFilesOlderThen
import org.apache.commons.io.filefilter.AgeFileFilter; //导入依赖的package包/类
private void deleteBackupFilesOlderThen(File backupDir, int days){
try {
if (backupDir.isDirectory()) {
Collection<File> filesToDelete = FileUtils.listFiles(backupDir,
new AgeFileFilter(DateUtils.addDays(new Date(), days * -1)),
TrueFileFilter.TRUE);
for (File file : filesToDelete) {
boolean success = FileUtils.deleteQuietly(file);
if (!success) {
LoggerFactory.getLogger(getClass())
.warn("Cannot delete old backup file at: " + file.getAbsolutePath());
}
}
}
} catch (Exception e) {
LoggerFactory.getLogger(getClass()).warn("Cannot delete old backup files.", e);
}
}
开发者ID:elexis,项目名称:elexis-3-core,代码行数:19,代码来源:LocalDocumentService.java
示例3: cleanup
import org.apache.commons.io.filefilter.AgeFileFilter; //导入依赖的package包/类
void cleanup() {
String taskLogsHome = getTaskLogHome();
if (taskLogsHome == null) {
// we are forgiving if the task logs home is not defined. Just log a message with a call to action.
log.warn("Unable to cleanup task log files. Please check that the 'tasklogfile' appender exists in logback.xml");
return;
}
File logFilesHome = new File(taskLogsHome);
log.info("Cleaning up log files in {} older than {} days", logFilesHome.getAbsolutePath(), numberOfDays);
LocalDate now = LocalDate.now().minusDays(numberOfDays);
Date thresholdDate = Date.from(now.atStartOfDay(ZoneId.systemDefault()).toInstant());
AgeFileFilter ageFileFilter = new AgeFileFilter(thresholdDate);
Iterator<File> filesToDelete = iterateFiles(logFilesHome, ageFileFilter, ageFileFilter);
filesToDelete.forEachRemaining(f -> {
try {
forceDelete(f);
log.info("Removed task log file {}", f.toString());
}
catch (IOException e) { // NOSONAR
log.error("Unable to delete task file {}. Message was {}.", f.toString(), e.getMessage());
}
}
);
}
开发者ID:sonatype,项目名称:nexus-public,代码行数:29,代码来源:TaskLogCleanup.java
示例4: removeAgedDeletedSegments
import org.apache.commons.io.filefilter.AgeFileFilter; //导入依赖的package包/类
/**
* Removes aged deleted segments from the deleted directory
* @param retentionInDays: retention for deleted segments in days
*/
public void removeAgedDeletedSegments(int retentionInDays) {
if (_localDiskDir != null) {
File deletedDir = new File(_localDiskDir, DELETED_SEGMENTS);
// Check that the directory for deleted segments exists
if (!deletedDir.isDirectory()) {
LOGGER.warn("Deleted segment directory {} does not exist or it is not directory.", deletedDir.getAbsolutePath());
return;
}
AgeFileFilter fileFilter = new AgeFileFilter(DateTime.now().minusDays(retentionInDays).toDate());
File[] directories = deletedDir.listFiles((FileFilter) DirectoryFileFilter.DIRECTORY);
// Check that the directory for deleted segments is empty
if (directories == null) {
LOGGER.warn("Deleted segment directory {} does not exist or it caused an I/O error.", deletedDir);
return;
}
for (File currentDir : directories) {
// Get files that are aged
Collection<File> targetFiles = FileUtils.listFiles(currentDir, fileFilter, null);
// Delete aged files
for (File f : targetFiles) {
if (!f.delete()) {
LOGGER.warn("Cannot remove file {} from deleted directory.", f.getAbsolutePath());
}
}
// Delete directory if it's empty
if (currentDir.list() != null && currentDir.list().length == 0) {
if (!currentDir.delete()) {
LOGGER.warn("The directory {} cannot be removed. The directory may not be empty.", currentDir.getAbsolutePath());
}
}
}
} else {
LOGGER.info("localDiskDir is not configured, won't delete any expired segments from deleted directory.");
}
}
开发者ID:linkedin,项目名称:pinot,代码行数:42,代码来源:SegmentDeletionManager.java
示例5: autoExportStatistics
import org.apache.commons.io.filefilter.AgeFileFilter; //导入依赖的package包/类
/**
* Automatically exports the usage statistics to a file. All files older then 30 days from the
* statistics directory will be deleted. This method can only be executed once.
*
* @throws IOException
*/
public void autoExportStatistics()
throws IOException{
TimeTool t = new TimeTool(System.currentTimeMillis());
String dir = CoreHub.getWritableUserDir().getAbsolutePath() + File.separator + "statistics";
String fileName = "usage" + t.toString(TimeTool.TIMESTAMP) + ".xml";
if (!disableAutoExport) {
try {
File directory = new File(dir);
if (directory.isDirectory()) {
Collection<File> filesToDelete = FileUtils.listFiles(directory,
new AgeFileFilter(DateUtils.addDays(new Date(), -30)), TrueFileFilter.TRUE);
for (File file : filesToDelete) {
boolean success = FileUtils.deleteQuietly(file);
if (!success) {
LoggerFactory.getLogger(getClass())
.warn("Cannot delete old file at: " + file.getAbsolutePath());
}
}
}
} catch (Exception e) {
LoggerFactory.getLogger(getClass()).warn("Cannot delete old files.", e);
}
exportStatisticsToFile(dir + File.separator + fileName);
disableAutoExport = true;
}
}
开发者ID:elexis,项目名称:elexis-3-core,代码行数:33,代码来源:StatisticsManager.java
示例6: setupFS
import org.apache.commons.io.filefilter.AgeFileFilter; //导入依赖的package包/类
private void setupFS() throws IOException {
log.config("Setting up filesystem...");
Collection<File> directories = new ArrayList<File>();
File reportsfolder = new File("ng-reports");
directories.add(bridge.getNGFolder());
directories.add(new File(bridge.getNGFolder(), "config"));
directories.add(new File(bridge.getNGFolder(), "data"));
directories.add(new File(bridge.getNGFolder(), "commands"));
directories.add(new File(bridge.getNGFolder(), "scripts"));
directories.add(reportsfolder);
for (File f : directories) {
if (f == null) continue;
if (!f.exists()) {
f.mkdir();
} else {
if (!f.isDirectory()) {
if (f.delete()) {
f.mkdir();
} else {
reportError(new IOException("Cannot fix " + f.getName() + "."));
}
}
}
}
if (!System.getProperty("nekoooguilds.dontcleanreports", "false").equalsIgnoreCase("true")) {
log.config("Cleaning up old reports...");
LocalDate today = LocalDate.now();
LocalDate eailer = today.minusDays(14);
Date threshold = Date.from(eailer.atStartOfDay(ZoneId.systemDefault()).toInstant());
AgeFileFilter filter = new AgeFileFilter(threshold);
File[] remove = FileFilterUtils.filter(filter, reportsfolder);
for (File file : remove) {
if (file.delete()) log.config("Deleted " + file.getName());
}
} else {
log.info("Report cleanup disabled with JVM/PropertyLoader option.");
}
}
开发者ID:NekoooGuilds,项目名称:NekoooGuilds,代码行数:47,代码来源:NekoooGuilds.java
示例7: executeReadFolder
import org.apache.commons.io.filefilter.AgeFileFilter; //导入依赖的package包/类
protected void executeReadFolder(final CommandLine cmdLine) throws IOException,
JMSException, ScriptException {
final long fileAgeMS = 1000;
String pathFilter = cmdLine.getOptionValue(CMD_READ_FOLDER);
if( pathFilter.isEmpty() ){
output("Option " + CMD_READ_FOLDER + " requires a path and wildcard filename.");
}
// expression will be like: /path/to/file/*.txt
// Last index of / will divide filter from path
File directory = Paths.get(".").toFile();
String filter = pathFilter;
int indexOfPathFilterSeparator = pathFilter.lastIndexOf('/');
if( indexOfPathFilterSeparator > 0){ // path + filename/filter
String path = pathFilter.substring(0, indexOfPathFilterSeparator);
directory = new File(path);
if ( pathFilter.endsWith("/")) {
output("Option " + CMD_READ_FOLDER + " cannot end with /. Please pass a wildcard filename after path.");
return;
} else {
filter = pathFilter.substring(indexOfPathFilterSeparator + 1);
}
}
AndFileFilter fileFilters = new AndFileFilter();
fileFilters.addFileFilter(new WildcardFileFilter(filter));
fileFilters.addFileFilter(new AgeFileFilter(System.currentTimeMillis() - fileAgeMS));
long startTime = System.currentTimeMillis();
long waitTime = Long.parseLong(cmdLine.getOptionValue(CMD_WAIT,"0"));
long endTime = startTime + waitTime;
do {
Collection<File> files = FileUtils.listFiles(directory, fileFilters, null); // no recursion
for(File file : files) {
putData("@"+file.getAbsolutePath(),cmdLine);
if (!file.delete()) {
output("Failed to delete file " + file.getName());
}
output("File " + file.getName() + " sent");
}
try {
Thread.sleep(SLEEP_TIME_BETWEEN_FILE_CHECK);
} catch (InterruptedException e) {
output("Interrupted");
break;
}
} while( endTime > System.currentTimeMillis());
}
开发者ID:fmtn,项目名称:a,代码行数:50,代码来源:A.java
示例8: push
import org.apache.commons.io.filefilter.AgeFileFilter; //导入依赖的package包/类
@Action(value = "/admin/push",
results = {
@Result(name = "success", location = "/admin/upload_result.jsp")
}
)
public String push() {
Long userId=AuthUtil.getUserId(servletRequest.getSession());
Long sessionId=AuthUtil.getSessionId(servletRequest.getSession());
try {
//get next pending system
pendingSystemStatus = SystemStatusDB.getNextPendingSystem(userId);
if (pendingSystemStatus != null) {
//get session for system
SchSession session = null;
for(Integer instanceId : SecureShellAction.getUserSchSessionMap().get(sessionId).getSchSessionMap().keySet()) {
//if host system id matches pending system then upload
if(pendingSystemStatus.getId().equals(SecureShellAction.getUserSchSessionMap().get(sessionId).getSchSessionMap().get(instanceId).getHostSystem().getId())){
session = SecureShellAction.getUserSchSessionMap().get(sessionId).getSchSessionMap().get(instanceId);
}
}
if(session!=null) {
//push upload to system
currentSystemStatus = SSHUtil.pushUpload(pendingSystemStatus, session.getSession(), UPLOAD_PATH + "/" + uploadFileName, pushDir + "/" + uploadFileName);
//update system status
SystemStatusDB.updateSystemStatus(currentSystemStatus, userId);
pendingSystemStatus = SystemStatusDB.getNextPendingSystem(userId);
}
}
//if push has finished to all servers then delete uploaded file
if (pendingSystemStatus == null) {
File delFile = new File(UPLOAD_PATH, uploadFileName);
FileUtils.deleteQuietly(delFile);
//delete all expired files in upload path
File delDir = new File(UPLOAD_PATH);
if (delDir.isDirectory()) {
//set expire time to delete all files older than 48 hrs
Calendar expireTime = Calendar.getInstance();
expireTime.add(Calendar.HOUR, - 48);
Iterator<File> filesToDelete = FileUtils.iterateFiles(delDir, new AgeFileFilter(expireTime.getTime()), TrueFileFilter.TRUE);
while(filesToDelete.hasNext()) {
delFile=filesToDelete.next();
delFile.delete();
}
}
}
hostSystemList = SystemStatusDB.getAllSystemStatus(userId);
} catch (Exception e) {
log.error(e.toString(), e);
}
return SUCCESS;
}
开发者ID:skavanagh,项目名称:EC2Box,代码行数:70,代码来源:UploadAndPushAction.java
示例9: cleanOldFiles
import org.apache.commons.io.filefilter.AgeFileFilter; //导入依赖的package包/类
/**
* Walks the baseDir recursively and deletes files and directories older than cutoff.
* When traversing directories, does not follow symbolic links.
*
* If a directory is old but contains files (which are not too old), it is not deleted.
*
* TODO better problem handling?
*
* @param baseDir
* @param cutoff milliseconds
* @throws IOException
*/
public static void cleanOldFiles(File baseDir, long cutoff ) throws IOException {
walkAndDelete(baseDir, new AgeFileFilter(System.currentTimeMillis() - cutoff));
}
开发者ID:chipster,项目名称:chipster,代码行数:16,代码来源:Files.java
注:本文中的org.apache.commons.io.filefilter.AgeFileFilter类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论