List of usage examples for java.io File lastModified
public long lastModified()
From source file:com.ms.commons.fasttext.FasttextService.java
private static void reload() { logger.info("????..."); if (!checkFile(false)) { logger.info("????,?"); return;/*w w w. ja v a 2 s. c om*/ } String path = System.getProperty(BANNED_DIR); String weijinfilename = path + File.separator + BANNEDWORD; String forkfilename = path + File.separator + RADICALDIC; String homofilename = path + File.separator + HOMOPHONE; File wf = new File(weijinfilename); File ff = new File(forkfilename); File hf = new File(homofilename); if (weijinLastModified != wf.lastModified() || forkLastModified != ff.lastModified() || homoLastModified != hf.lastModified()) { // ?,? logger.info("??,????....?..."); loadText(); logger.info("????....?..."); } else { logger.info("?,?..."); } }
From source file:com.tascape.qa.th.Utils.java
/** * * @param path directory to clean * @param keepAliveHour any file/directory having last modified time longer than keepAliveHour will be deleted * @param namePrefix file name prefix *//*from w w w . ja v a2 s . com*/ public static void cleanDirectory(final String path, final float keepAliveHour, final String namePrefix) { final long intervalMillis = 3600000; final File dir = new File(path); if (!dir.exists()) { return; } Thread thread = new Thread() { @Override public void run() { while (true) { long lastModifiedMillis = (long) (System.currentTimeMillis() - keepAliveHour * 3600000); Collection<File> files = FileUtils.listFiles(dir, null, true); for (File file : files) { if (file.lastModified() < lastModifiedMillis && file.getName().startsWith(namePrefix)) { LOG.debug("Delete {}", file); if (!FileUtils.deleteQuietly(file)) { LOG.debug("Cannot delete {}", file); } } } try { LOG.debug("Waiting for next cleanup..."); Thread.sleep(intervalMillis); } catch (InterruptedException ex) { LOG.warn(ex.getMessage()); return; } } } }; thread.setName(Thread.currentThread().getName() + "-cleaning-" + thread.hashCode()); thread.setDaemon(true); LOG.info( "Starting directory cleaning thread (scanning hourly), all files/directories in {} and older than {} " + "hour(s) and starts with {} will be deleted", dir, keepAliveHour, namePrefix); thread.start(); }
From source file:com.twinsoft.convertigo.engine.util.ZipUtils.java
private static int putEntries(ZipOutputStream zos, String sDir, String sRelativeDir, final List<File> excludedFiles) throws Exception { Engine.logEngine.trace("=========================================================="); Engine.logEngine.trace("sDir=" + sDir); Engine.logEngine.trace("sRelativeDir=" + sRelativeDir); Engine.logEngine.trace("excludedFiles=" + excludedFiles); File dir = new File(sDir); String[] files = dir.list(new FilenameFilter() { public boolean accept(File dir, String name) { File file = new File(dir, name); return (!excludedFiles.contains(file)); }/*w ww.ja va 2 s . co m*/ }); Engine.logEngine.trace("files=" + files); int nbe = 0; for (String file : files) { String sDirEntry = sDir + "/" + file; String sRelativeDirEntry = sRelativeDir != null ? (sRelativeDir + "/" + file) : file; File f = new File(sDirEntry); if (!f.isDirectory()) { Engine.logEngine.trace("+ " + sDirEntry); InputStream fi = new FileInputStream(f); try { ZipEntry entry = new ZipEntry(sRelativeDirEntry); entry.setTime(f.lastModified()); zos.putNextEntry(entry); IOUtils.copy(fi, zos); nbe++; } finally { fi.close(); } } else { nbe += putEntries(zos, sDirEntry, sRelativeDirEntry, excludedFiles); } } return nbe; }
From source file:net.sf.gazpachoquest.rest.auth.TokenStore.java
/** * Creates a byte array of entry from the current state of the system: * <ul>//from w w w . ja v a 2 s. c o m * <li>The current system time in milliseconds since the epoch</li> * <li>The number of nanoseconds since system startup</li> * <li>The name, size and last modification time of the files in the * <code>java.io.tmpdir</code> folder.</li> * </ul> * <p> * <b>NOTE</b> This method generates entropy fast but not necessarily * secure enough for seeding the random number generator. * * @return bytes of entropy */ private static byte[] getFastEntropy() { final MessageDigest md; try { md = MessageDigest.getInstance("SHA"); } catch (NoSuchAlgorithmException nsae) { throw new InternalError("internal error: SHA-1 not available."); } // update with XorShifted time values update(md, System.currentTimeMillis()); update(md, System.nanoTime()); // scan the temp file system File file = new File(System.getProperty("java.io.tmpdir")); File[] entries = file.listFiles(); if (entries != null) { for (File entry : entries) { md.update(entry.getName().getBytes()); update(md, entry.lastModified()); update(md, entry.length()); } } return md.digest(); }
From source file:com.manydesigns.portofino.dispatcher.DispatcherLogic.java
public static void initPageCache(int maxSize, int refreshCheckFrequency) { pageCache = CacheBuilder.newBuilder().maximumSize(maxSize) .refreshAfterWrite(refreshCheckFrequency, TimeUnit.SECONDS) .build(new CacheLoader<File, FileCacheEntry<Page>>() { @Override/*from ww w . j ava 2 s .com*/ public FileCacheEntry<Page> load(File key) throws Exception { return new FileCacheEntry<Page>(loadPage(key), key.lastModified(), false); } @Override public ListenableFuture<FileCacheEntry<Page>> reload(final File key, FileCacheEntry<Page> oldValue) throws Exception { if (!key.exists()) { //Se la pagina non esiste pi, registro questo fatto nella cache; //a questo livello non un errore, sar il metodo getPage() a gestire //la entry problematica. return Futures.immediateFuture(new FileCacheEntry<Page>(null, 0, true)); } else if (key.lastModified() > oldValue.lastModified) { /*return ListenableFutureTask.create(new Callable<PageCacheEntry>() { public PageCacheEntry call() throws Exception { return doLoad(key); } });*/ //TODO async? try { Page page = loadPage(key); return Futures .immediateFuture(new FileCacheEntry<Page>(page, key.lastModified(), false)); } catch (Throwable t) { logger.error("Could not reload cached page from " + key.getAbsolutePath() + ", removing from cache", t); return Futures .immediateFuture(new FileCacheEntry<Page>(null, key.lastModified(), true)); } } else { return Futures.immediateFuture(oldValue); } } }); }
From source file:de.clusteval.run.result.RunDataAnalysisRunResult.java
/** * @param parentRepository/*w w w.j av a2 s .co m*/ * @param runResultFolder * @return The run-data analysis runresult parsed from the given runresult * folder. * * @throws RepositoryAlreadyExistsException * @throws RepositoryAlreadyExistsException * @throws InvalidRepositoryException * @throws UnknownDistanceMeasureException * @throws IncompatibleParameterOptimizationMethodException * @throws UnknownRProgramException * @throws UnknownProgramTypeException * @throws UnknownDataStatisticException * @throws RunException * @throws InvalidOptimizationParameterException * @throws GoldStandardNotFoundException * @throws NoRepositoryFoundException * @throws UnknownProgramParameterException * @throws NoOptimizableProgramParameterException * @throws UnknownParameterOptimizationMethodException * @throws InvalidRunModeException * @throws UnknownClusteringQualityMeasureException * @throws InvalidConfigurationFileException * @throws UnknownDataSetFormatException * @throws UnknownRunResultFormatException * @throws IOException * @throws DataConfigNotFoundException * @throws DataConfigurationException * @throws GoldStandardConfigNotFoundException * @throws DataSetConfigNotFoundException * @throws DataSetNotFoundException * @throws DataSetConfigurationException * @throws GoldStandardConfigurationException * @throws UnknownRunStatisticException * @throws UnknownGoldStandardFormatException * @throws RepositoryConfigurationException * @throws RepositoryConfigNotFoundException * @throws ConfigurationException * @throws RegisterException * @throws UnknownDataSetTypeException * @throws NoDataSetException * @throws NumberFormatException * @throws UnknownRunDataStatisticException * @throws RunResultParseException * @throws UnknownDataPreprocessorException * @throws IncompatibleDataSetConfigPreprocessorException * @throws UnknownContextException * @throws IncompatibleContextException * @throws UnknownParameterType * @throws InterruptedException */ public static RunDataAnalysisRunResult parseFromRunResultFolder(final Repository parentRepository, final File runResultFolder) throws RepositoryAlreadyExistsException, InvalidRepositoryException, GoldStandardConfigurationException, DataSetConfigurationException, DataSetNotFoundException, DataSetConfigNotFoundException, GoldStandardConfigNotFoundException, DataConfigurationException, DataConfigNotFoundException, IOException, UnknownRunResultFormatException, UnknownDataSetFormatException, InvalidConfigurationFileException, UnknownClusteringQualityMeasureException, InvalidRunModeException, UnknownParameterOptimizationMethodException, NoOptimizableProgramParameterException, UnknownProgramParameterException, NoRepositoryFoundException, GoldStandardNotFoundException, InvalidOptimizationParameterException, RunException, UnknownDataStatisticException, UnknownProgramTypeException, UnknownRProgramException, IncompatibleParameterOptimizationMethodException, UnknownDistanceMeasureException, UnknownRunStatisticException, UnknownGoldStandardFormatException, RepositoryConfigNotFoundException, RepositoryConfigurationException, ConfigurationException, RegisterException, UnknownDataSetTypeException, NumberFormatException, NoDataSetException, UnknownRunDataStatisticException, RunResultParseException, UnknownDataPreprocessorException, IncompatibleDataSetConfigPreprocessorException, UnknownContextException, IncompatibleContextException, UnknownParameterType, InterruptedException { Repository childRepository = new RunResultRepository(runResultFolder.getAbsolutePath(), parentRepository); childRepository.initialize(); File runFile = null; File configFolder = new File(FileUtils.buildPath(runResultFolder.getAbsolutePath(), "configs")); if (!configFolder.exists()) return null; for (File child : configFolder.listFiles()) if (child.getName().endsWith(".run")) { runFile = child; break; } if (runFile == null) return null; final Run run = Parser.parseRunFromFile(runFile); RunDataAnalysisRunResult analysisResult = null; if (run instanceof RunDataAnalysisRun) { final RunDataAnalysisRun runDataRun = (RunDataAnalysisRun) run; File analysesFolder = new File(FileUtils.buildPath(runResultFolder.getAbsolutePath(), "analyses")); analysisResult = new RunDataAnalysisRunResult(parentRepository, analysesFolder.lastModified(), analysesFolder, analysesFolder.getParentFile().getName(), runDataRun); analysisResult.loadIntoMemory(); try { analysisResult.register(); } finally { analysisResult.unloadFromMemory(); } } return analysisResult; }
From source file:de.clusteval.run.result.RunAnalysisRunResult.java
/** * @param repository/* w ww.j a va 2 s.c o m*/ * The repository in which we want to register the parsed * runresult. * @param runResultFolder * The runresult folder from which we want to parse the * runresult. * @return The run analysis runresult parsed from the runresult folder. * * @throws RepositoryAlreadyExistsException * @throws RepositoryAlreadyExistsException * @throws InvalidRepositoryException * @throws UnknownRunStatisticException * @throws UnknownDistanceMeasureException * @throws IncompatibleParameterOptimizationMethodException * @throws UnknownRProgramException * @throws UnknownProgramTypeException * @throws UnknownDataStatisticException * @throws RunException * @throws InvalidOptimizationParameterException * @throws GoldStandardNotFoundException * @throws NoRepositoryFoundException * @throws UnknownProgramParameterException * @throws NoOptimizableProgramParameterException * @throws UnknownParameterOptimizationMethodException * @throws InvalidRunModeException * @throws UnknownClusteringQualityMeasureException * @throws InvalidConfigurationFileException * @throws UnknownDataSetFormatException * @throws UnknownRunResultFormatException * @throws IOException * @throws DataConfigNotFoundException * @throws DataConfigurationException * @throws GoldStandardConfigNotFoundException * @throws DataSetConfigNotFoundException * @throws DataSetNotFoundException * @throws DataSetConfigurationException * @throws GoldStandardConfigurationException * @throws UnknownGoldStandardFormatException * @throws RepositoryConfigurationException * @throws RepositoryConfigNotFoundException * @throws ConfigurationException * @throws RegisterException * @throws UnknownDataSetTypeException * @throws NoDataSetException * @throws NumberFormatException * @throws UnknownRunDataStatisticException * @throws RunResultParseException * @throws UnknownDataPreprocessorException * @throws IncompatibleDataSetConfigPreprocessorException * @throws UnknownContextException * @throws IncompatibleContextException * @throws UnknownParameterType * @throws InterruptedException */ public static RunAnalysisRunResult parseFromRunResultFolder(final Repository repository, final File runResultFolder) throws RepositoryAlreadyExistsException, InvalidRepositoryException, GoldStandardConfigurationException, DataSetConfigurationException, DataSetNotFoundException, DataSetConfigNotFoundException, GoldStandardConfigNotFoundException, DataConfigurationException, DataConfigNotFoundException, IOException, UnknownRunResultFormatException, UnknownDataSetFormatException, InvalidConfigurationFileException, UnknownClusteringQualityMeasureException, InvalidRunModeException, UnknownParameterOptimizationMethodException, NoOptimizableProgramParameterException, UnknownProgramParameterException, NoRepositoryFoundException, GoldStandardNotFoundException, InvalidOptimizationParameterException, RunException, UnknownDataStatisticException, UnknownProgramTypeException, UnknownRProgramException, IncompatibleParameterOptimizationMethodException, UnknownDistanceMeasureException, UnknownRunStatisticException, UnknownGoldStandardFormatException, RepositoryConfigNotFoundException, RepositoryConfigurationException, ConfigurationException, RegisterException, UnknownDataSetTypeException, NumberFormatException, NoDataSetException, UnknownRunDataStatisticException, RunResultParseException, UnknownDataPreprocessorException, IncompatibleDataSetConfigPreprocessorException, UnknownContextException, IncompatibleContextException, UnknownParameterType, InterruptedException { Repository childRepository = new RunResultRepository(runResultFolder.getAbsolutePath(), repository); childRepository.initialize(); File runFile = null; File configFolder = new File(FileUtils.buildPath(runResultFolder.getAbsolutePath(), "configs")); if (!configFolder.exists()) return null; for (File child : configFolder.listFiles()) if (child.getName().endsWith(".run")) { runFile = child; break; } if (runFile == null) return null; final Run object = Parser.parseRunFromFile(runFile); RunAnalysisRunResult analysisResult = null; if (object instanceof RunAnalysisRun) { final RunAnalysisRun run = (RunAnalysisRun) object; File analysesFolder = new File(FileUtils.buildPath(runResultFolder.getAbsolutePath(), "analyses")); analysisResult = new RunAnalysisRunResult(repository, false, analysesFolder.lastModified(), analysesFolder, analysesFolder.getParentFile().getName(), run); analysisResult.loadIntoMemory(); try { analysisResult.register(); } finally { analysisResult.unloadFromMemory(); } } return analysisResult; }
From source file:com.t3.persistence.FileUtil.java
public static void delete(File file, int daysOld) throws IOException { Calendar olderThan = new GregorianCalendar(); olderThan.add(Calendar.DATE, -daysOld); boolean shouldDelete = new Date(file.lastModified()).before(olderThan.getTime()); if (file.isDirectory()) { // Wipe the contents first for (File currfile : file.listFiles()) { if (".".equals(currfile.getName()) || "..".equals(currfile.getName())) continue; delete(currfile, daysOld);//from ww w .j a v a2s . com } } if (shouldDelete) file.delete(); }
From source file:de.clusteval.run.result.DataAnalysisRunResult.java
/** * @param parentRepository//from w w w. j av a2 s . com * @param runResultFolder * @return The data analysis run result parsed from the given runresult * folder. * * @throws RepositoryAlreadyExistsException * @throws RepositoryAlreadyExistsException * @throws InvalidRepositoryException * @throws UnknownRunStatisticException * @throws UnknownDistanceMeasureException * @throws IncompatibleParameterOptimizationMethodException * @throws UnknownRProgramException * @throws UnknownProgramTypeException * @throws UnknownDataStatisticException * @throws RunException * @throws InvalidOptimizationParameterException * @throws GoldStandardNotFoundException * @throws NoRepositoryFoundException * @throws UnknownProgramParameterException * @throws NoOptimizableProgramParameterException * @throws UnknownParameterOptimizationMethodException * @throws InvalidRunModeException * @throws UnknownClusteringQualityMeasureException * @throws InvalidConfigurationFileException * @throws UnknownDataSetFormatException * @throws UnknownRunResultFormatException * @throws IOException * @throws DataConfigNotFoundException * @throws DataConfigurationException * @throws GoldStandardConfigNotFoundException * @throws DataSetConfigNotFoundException * @throws DataSetNotFoundException * @throws DataSetConfigurationException * @throws GoldStandardConfigurationException * @throws UnknownGoldStandardFormatException * @throws AnalysisRunResultException * @throws RepositoryConfigurationException * @throws RepositoryConfigNotFoundException * @throws ConfigurationException * @throws RegisterException * @throws UnknownDataSetTypeException * @throws NoDataSetException * @throws NumberFormatException * @throws UnknownRunDataStatisticException * @throws UnknownDataPreprocessorException * @throws IncompatibleDataSetConfigPreprocessorException * @throws UnknownContextException * @throws IncompatibleContextException * @throws UnknownParameterType * @throws InterruptedException */ public static DataAnalysisRunResult parseFromRunResultFolder(final Repository parentRepository, final File runResultFolder) throws RepositoryAlreadyExistsException, InvalidRepositoryException, GoldStandardConfigurationException, DataSetConfigurationException, DataSetNotFoundException, DataSetConfigNotFoundException, GoldStandardConfigNotFoundException, DataConfigurationException, DataConfigNotFoundException, IOException, UnknownRunResultFormatException, UnknownDataSetFormatException, InvalidConfigurationFileException, UnknownClusteringQualityMeasureException, InvalidRunModeException, UnknownParameterOptimizationMethodException, NoOptimizableProgramParameterException, UnknownProgramParameterException, NoRepositoryFoundException, GoldStandardNotFoundException, InvalidOptimizationParameterException, RunException, UnknownDataStatisticException, UnknownProgramTypeException, UnknownRProgramException, IncompatibleParameterOptimizationMethodException, UnknownDistanceMeasureException, UnknownRunStatisticException, UnknownGoldStandardFormatException, AnalysisRunResultException, RepositoryConfigNotFoundException, RepositoryConfigurationException, ConfigurationException, RegisterException, UnknownDataSetTypeException, NumberFormatException, NoDataSetException, UnknownRunDataStatisticException, UnknownDataPreprocessorException, IncompatibleDataSetConfigPreprocessorException, UnknownContextException, IncompatibleContextException, UnknownParameterType, InterruptedException { Repository childRepository = new RunResultRepository(runResultFolder.getAbsolutePath(), parentRepository); childRepository.initialize(); File runFile = null; File configFolder = new File(FileUtils.buildPath(runResultFolder.getAbsolutePath(), "configs")); if (!configFolder.exists()) return null; for (File child : configFolder.listFiles()) if (child.getName().endsWith(".run")) { runFile = child; break; } if (runFile == null) return null; final Run object = Parser.parseRunFromFile(runFile); DataAnalysisRunResult analysisResult = null; if (object instanceof DataAnalysisRun) { final DataAnalysisRun run = (DataAnalysisRun) object; File analysesFolder = new File(FileUtils.buildPath(runResultFolder.getAbsolutePath(), "analyses")); analysisResult = new DataAnalysisRunResult(parentRepository, analysesFolder.lastModified(), analysesFolder, analysesFolder.getParentFile().getName(), run); for (final DataConfig dataConfig : run.getDataConfigs()) { List<DataStatistic> statistics = new ArrayList<DataStatistic>(); for (final Statistic dataStatistic : run.getStatistics()) { final File completeFile = new File(FileUtils.buildPath(analysesFolder.getAbsolutePath(), dataConfig.toString() + "_" + dataStatistic.getIdentifier() + ".txt")); if (!completeFile.exists()) throw new AnalysisRunResultException("The result file of (" + dataConfig + "," + dataStatistic.getIdentifier() + ") could not be found: " + completeFile); final String fileContents = FileUtils.readStringFromFile(completeFile.getAbsolutePath()); dataStatistic.parseFromString(fileContents); statistics.add((DataStatistic) dataStatistic); } analysisResult.put(dataConfig, statistics); } analysisResult.register(); } return analysisResult; }
From source file:com.netflix.ice.common.AwsUtils.java
public static boolean downloadFileIfChanged(String bucketName, String bucketFilePrefix, File file, long milles) { ObjectMetadata metadata = s3Client.getObjectMetadata(bucketName, bucketFilePrefix + file.getName()); boolean download = !file.exists() || metadata.getLastModified().getTime() > file.lastModified() + milles; logger.info("downloadFileIfChanged " + file + " " + metadata.getLastModified().getTime() + " " + (file.lastModified() + milles)); if (download) { return download(bucketName, bucketFilePrefix + file.getName(), file); } else/*from w w w . j a v a2 s.co m*/ return false; }