Example usage for org.apache.commons.io FileUtils isFileOlder

List of usage examples for org.apache.commons.io FileUtils isFileOlder

Introduction

In this page you can find the example usage for org.apache.commons.io FileUtils isFileOlder.

Prototype

public static boolean isFileOlder(File file, long timeMillis) 

Source Link

Document

Tests if the specified File is older than the specified time reference.

Usage

From source file:org.niord.core.repo.RepositoryService.java

/**
 * Recursively delete one day old files and folders
 * @param file the current root file or folder
 * @param date the expiry date/* w  ww. j  a v a 2  s .c o m*/
 */
private void checkDeletePath(File file, Date date) {
    if (FileUtils.isFileOlder(file, date)) {
        log.debug("Deleting expired temp file or folder: " + file);
        FileUtils.deleteQuietly(file);
    } else if (file.isDirectory()) {
        File[] files = file.listFiles();
        if (files != null && files.length > 0) {
            Arrays.asList(files).forEach(f -> checkDeletePath(f, date));
        }
    }
}

From source file:org.silverpeas.core.process.io.file.FileHandler.java

/**
 * @see FileUtils/*  w ww .j av  a2s .  co  m*/
 */
protected boolean isFileOlder(final FileBasePath basePath, final File file, final File reference) {
    verify(basePath, file);
    verify(basePath, reference);
    return FileUtils.isFileOlder(getExistingFile(basePath, file), getExistingFile(basePath, reference));
}

From source file:org.silverpeas.core.process.io.file.FileHandler.java

/**
 * @see FileUtils// www  .ja  va  2 s .  c  om
 */
protected boolean isFileOlder(final FileBasePath basePath, final File file, final Date date) {
    verify(basePath, file);
    return FileUtils.isFileOlder(getExistingFile(basePath, file), date);
}

From source file:org.silverpeas.core.process.io.file.FileHandler.java

/**
 * @see FileUtils// w  ww  .  j a v  a  2s .c o  m
 */
protected boolean isFileOlder(final FileBasePath basePath, final File file, final long timeMillis) {
    verify(basePath, file);
    return FileUtils.isFileOlder(getExistingFile(basePath, file), timeMillis);
}

From source file:tv.phantombot.PhantomBot.java

/**
 * Backup the database, keeping so many days.
 *//*from   ww w.j av a2 s  .c  o m*/
private void doBackupSQLiteDB() {

    if (!dataStoreType.equals("sqlite3store")) {
        return;
    }

    ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor();
    service.scheduleAtFixedRate(() -> {
        Thread.currentThread().setName("tv.phantombot.PhantomBot::doBackupSQLiteDB");

        SimpleDateFormat datefmt = new SimpleDateFormat("ddMMyyyy.hhmmss");
        datefmt.setTimeZone(TimeZone.getTimeZone(timeZone));
        String timestamp = datefmt.format(new Date());

        dataStore.backupSQLite3("phantombot.auto.backup." + timestamp + ".db");

        try {
            Iterator dirIterator = FileUtils.iterateFiles(new File("./dbbackup"),
                    new WildcardFileFilter("phantombot.auto.*"), null);
            while (dirIterator.hasNext()) {
                File backupFile = (File) dirIterator.next();
                if (FileUtils.isFileOlder(backupFile,
                        (System.currentTimeMillis() - (long) (backupSQLiteKeepDays * 864e5)))) {
                    FileUtils.deleteQuietly(backupFile);
                }
            }
        } catch (Exception ex) {
            com.gmt2001.Console.err.println("Failed to clean up database backup directory: " + ex.getMessage());
        }
    }, 0, backupSQLiteHourFrequency, TimeUnit.HOURS);
}