Java Code Examples for org.apache.commons.io.FileUtils.isFileOlder()

The following are Jave code examples for showing how to use isFileOlder() of the org.apache.commons.io.FileUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: mobile-store   File: CleanCacheService.java   View Source Code Vote up 6 votes
/**
 * Recursively delete files in {@code f} that were last used
 * {@code millisAgo} milliseconds ago.  On {@code android-21} and newer, this
 * is based on the last access of the file, on older Android versions, it is
 * based on the last time the file was modified, e.g. downloaded.
 *
 * @param f         The file or directory to clean
 * @param millisAgo The number of milliseconds old that marks a file for deletion.
 */
public static void clearOldFiles(File f, long millisAgo) {
    if (f == null) {
        return;
    }
    long olderThan = System.currentTimeMillis() - millisAgo;
    if (f.isDirectory()) {
        File[] files = f.listFiles();
        if (files == null) {
            return;
        }
        for (File file : files) {
            clearOldFiles(file, millisAgo);
        }
        f.delete();
    } else if (Build.VERSION.SDK_INT < 21) {
        if (FileUtils.isFileOlder(f, olderThan)) {
            f.delete();
        }
    } else {
        CleanCacheService21.deleteIfOld(f, olderThan);
    }
}
 
Example 2
Project: sjk   File: AppServiceImpl.java   View Source Code Vote up 5 votes
private void genetatePage(App app, Template template) {
    File file = new File(config.getAppDetailGenerateBasePath() + "/" + (app.getId() / 500) + "/" + app.getId()
            + ".html");
    if (!file.exists()
            || FileUtils.isFileOlder(file, app.geteUpdateDate() == null ? new Date() : app.geteUpdateDate())) {
        GenerateHelper.generateAppDetail(file, app, template, config);
        logger.debug(String.format("new genetate app ID:%d,  Name:%s, path:%s ", app.getId(), app.getName(),
                file.getPath()));
    }
}
 
Example 3
Project: sjk   File: AppServiceImpl.java   View Source Code Vote up 5 votes
@SuppressWarnings("unused")
private void genetatePageVelocity(App app, org.apache.velocity.Template template) {
    File file = new File(config.getAppDetailGenerateBasePath() + "/" + (app.getId() / 500) + "/" + app.getId()
            + ".html");
    if (!file.exists()
            || FileUtils.isFileOlder(file, app.geteUpdateDate() == null ? new Date() : app.geteUpdateDate())) {
        GenerateHelper.generateAppDetailByTemplate(file, app, template);
        logger.debug(String.format("new genetate app ID:%d,  Name:%s, path:%s ", app.getId(), app.getName(),
                file.getPath()));
    }
}
 
Example 4
Project: sjk   File: AppServiceImpl.java   View Source Code Vote up 4 votes
private void genetatePageVelocity(App app, org.apache.velocity.Template template, Catalog catalog,
        Map<Integer, Permissions> permissionsMap, List<AppTags> appTags, List<AppTags> AppTopic, boolean isAll) {

    // 过滤掉一些东西
    // 更新字段 过滤
    String updateInfo = app.getUpdateInfo();
    if (StringUtils.isNotEmpty(updateInfo)) {
        updateInfo = updateInfo.replaceAll("\r\n", "<br />").replaceAll("\n", "<br />");
        updateInfo = updateInfo.replaceAll("\\\\n", "");
        app.setUpdateInfo(updateInfo);
    }

    String description = app.getDescription();
    if (StringUtils.isNotEmpty(description)) {
        description = description.replaceAll("\r\n", "<br />").replaceAll("\n", "<br />");
        description = description.replaceAll("\\\\n", "");

        app.setDescription(description);
    }

    StringBuilder detailPath = new StringBuilder();
    detailPath.append("/").append(app.getId() / 500).append("/").append(app.getId()).append(".html");

    File file = new File(config.getAppDetailGenerateBasePath() + detailPath.toString());

    // if (StringUtils.isEmpty(app.getPageUrl())) {
    // 设置url
    app.setPageUrl(config.getAppPageBaseUrl() + detailPath.toString());

    // }

    // 根据分类查找对应的大游戏集合
    List<BigGamePack> bigGameList = bigGamePackDao.getBigGameByMarkAppId(app.getMarketAppId());

    // 如果 是取倒是,则不用判断 原文件是否存在 ,一律全部重新生成
    if (isAll) {
        GenerateHelper.generateAppDetailByTemplate(file, app, template, catalog, permissionsMap, appTags, AppTopic,
                bigGameList);

        dao.updatePageUrl(app);// 需要时才更新 db
        return;
    }

    // 如果模板的最后 修改时间 比 应用 新,则需要全部重新生成 ,而不用应用 判断 文件 是否存在
    if (!file.exists() || FileUtils.isFileOlder(file, template.getLastModified())
            || FileUtils.isFileOlder(file, app.getLastFetchTime() == null ? new Date() : app.getLastFetchTime())
            || FileUtils.isFileOlder(file, app.getLastUpdateTime() == null ? new Date() : app.getLastUpdateTime())) {

        GenerateHelper.generateAppDetailByTemplate(file, app, template, catalog, permissionsMap, appTags, AppTopic,
                bigGameList);

        dao.updatePageUrl(app);// 需要时才更新 db
    }
}
 
Example 5
Project: careconnect-reference-implementation   File: BaseCommand.java   View Source Code Vote up 4 votes
protected Collection<File> loadFile(FhirContext theCtx, String theSpecUrl, String theFilepath, boolean theCacheFile) throws IOException {
	String userHomeDir = System.getProperty("user.home");

	File applicationDir = new File(userHomeDir + File.separator + "." + "hapi-fhir-cli");
	FileUtils.forceMkdir(applicationDir);

	Collection<File> inputFiles;
	if (isNotBlank(theFilepath)) {
		ourLog.info("Loading from local path: {}", theFilepath);

		if (theFilepath.startsWith("~" + File.separator)) {
			theFilepath = userHomeDir + theFilepath.substring(1);
		}

		File suppliedFile = new File(FilenameUtils.normalize(theFilepath));

		if (suppliedFile.isDirectory()) {
			inputFiles = FileUtils.listFiles(suppliedFile, new String[]{"zip"}, false);
		} else {
			inputFiles = Collections.singletonList(suppliedFile);
		}

	} else {

		File cacheDir = new File(applicationDir, "cache");
		FileUtils.forceMkdir(cacheDir);

		File inputFile = new File(cacheDir, "examples-json-" + theCtx.getVersion().getVersion() + ".zip");

		Date cacheExpiryDate = DateUtils.addHours(new Date(), -12);

		if (!inputFile.exists() | (theCacheFile && FileUtils.isFileOlder(inputFile, cacheExpiryDate))) {

			File exampleFileDownloading = new File(cacheDir, "examples-json-" + theCtx.getVersion().getVersion() + ".zip.partial");

			HttpGet get = new HttpGet(theSpecUrl);
			CloseableHttpClient client = HttpClientBuilder.create().build();
			CloseableHttpResponse result = client.execute(get);

			if (result.getStatusLine().getStatusCode() != 200) {
				throw new CommandFailureException("Got HTTP " + result.getStatusLine().getStatusCode() + " response code loading " + theSpecUrl);
			}

			ourLog.info("Downloading from remote url: {}", theSpecUrl);
			downloadFileFromInternet(result, exampleFileDownloading);

			FileUtils.deleteQuietly(inputFile);
			FileUtils.moveFile(exampleFileDownloading, inputFile);

			if (!theCacheFile) {
				inputFile.deleteOnExit();
			}

			ourLog.info("Successfully Loaded example pack ({})", FileUtils.byteCountToDisplaySize(FileUtils.sizeOf(inputFile)));
			IOUtils.closeQuietly(result.getEntity().getContent());
		}

		inputFiles = Collections.singletonList(inputFile);

	}
	return inputFiles;
}