List of usage examples for org.apache.commons.io FileUtils isFileNewer
public static boolean isFileNewer(File file, long timeMillis)
File
is newer than the specified time reference. From source file:info.fetter.logstashforwarder.util.LastModifiedFileFilter.java
@Override public boolean accept(File file) { long timeMillis = System.currentTimeMillis() - cutoff; if (after) {// w ww . j a v a 2s . c om return FileUtils.isFileNewer(file, timeMillis); } else { return FileUtils.isFileOlder(file, timeMillis); } }
From source file:com.haulmont.cuba.core.sys.javacl.CompilationScope.java
private void collectInformation(String rootClassName) throws ClassNotFoundException { if (processed.contains(rootClassName)) { return;/*from w ww. j a v a 2 s. c om*/ } File srcFile = sourceProvider.getSourceFile(rootClassName); processed.add(rootClassName); TimestampClass timeStampClazz = javaClassLoader.getTimestampClass(rootClassName); if (timeStampClazz != null) { if (FileUtils.isFileNewer(srcFile, timeStampClazz.timestamp)) { compilationNeeded.add(rootClassName); } else if (!srcFile.exists()) { throw new ClassNotFoundException( String.format("Class %s not found. No sources found in file system.", rootClassName)); } for (String dependencyName : timeStampClazz.dependencies) { collectInformation(dependencyName); } } else { compilationNeeded.add(rootClassName); } }
From source file:annis.security.ANNISRolePermissionResolver.java
private void checkConfiguration() { boolean reload = false; // get a read lock that does not block anyone else to find out if we need an update lock.readLock().lock();//from www. j av a 2 s. co m try { if (groupsFile == null) { return; } if (lastTimeReloaded == null || FileUtils.isFileNewer(groupsFile, lastTimeReloaded)) { reload = true; } } finally { lock.readLock().unlock(); } if (reload) { reloadGroups(); } }
From source file:annis.security.ANNISUserConfigurationManager.java
private void checkConfiguration() { boolean reload = false; // get a read lock that does not block anyone else to find out if we need an update lock.readLock().lock();/* w w w . j a v a 2 s .co m*/ try { if (groupsFile == null) { return; } if (lastTimeReloaded == null || FileUtils.isFileNewer(groupsFile, lastTimeReloaded)) { reload = true; } } finally { lock.readLock().unlock(); } if (reload) { reloadGroupsFromFile(); } }
From source file:alluxio.AlluxioTestDirectory.java
/** * Deletes files in the given directory which are older than 2 hours. * * @param dir the directory to clean up//w ww . j a v a 2 s . c o m */ private static void cleanUpOldFiles(File dir) { long cutoffTimestamp = System.currentTimeMillis() - (MAX_FILE_AGE_HOURS * Constants.HOUR_MS); File[] files = dir.listFiles(); for (File file : files) { if (!FileUtils.isFileNewer(file, cutoffTimestamp)) { try { alluxio.util.io.FileUtils.deletePathRecursively(file.getAbsolutePath()); } catch (Exception e) { LOG.warn("Failed to delete {} : {}", file.getAbsolutePath(), e.getMessage()); } } } }
From source file:edu.coeia.reports.IndexUtil.java
public static List<String> getAllFilesBetweenDates(final CaseFacade caseFacade, final Date from, final Date to) throws IOException { List<String> files = new ArrayList<String>(); for (String fileName : getAllFilePaths(caseFacade)) { File file = new File(fileName); if (FileUtils.isFileNewer(file, from) && FileUtils.isFileOlder(file, to)) { files.add(fileName);//w ww . ja v a 2s .c o m } } return files; }
From source file:com.sforce.cd.apexUnit.report.ApexReportGeneratorTest.java
@Test public void generateTestReportTest() { TestStatusPollerAndResultHandler queryPollerAndResultHandler = new TestStatusPollerAndResultHandler(); Long justBeforeReportGeneration = System.currentTimeMillis(); ApexReportBean[] apexReportBeans = queryPollerAndResultHandler.fetchResultsFromParentJobId(parentJobId, conn);/*w w w .j a v a 2 s . c o m*/ CodeCoverageComputer toolingAPIInvoker = new CodeCoverageComputer(); ApexClassCodeCoverageBean[] apexClassCodeCoverageBeans = toolingAPIInvoker .calculateAggregatedCodeCoverageUsingToolingAPI(); String reportFileName = "ApexUnitReport.xml"; ApexUnitTestReportGenerator.generateTestReport(apexReportBeans, reportFileName); File reportFile = new File(reportFileName); LOG.info("justBeforeReportGeneration: " + justBeforeReportGeneration); LOG.info("reportFile last modified..: " + reportFile.lastModified()); LOG.info("Result:" + FileUtils.isFileNewer(reportFile, justBeforeReportGeneration)); Assert.assertTrue(FileUtils.isFileNewer(reportFile, justBeforeReportGeneration)); }
From source file:middleware.LogTailer.java
@Override public void run() { RandomAccessFile reader = null; try {// ww w .j a v a 2 s . com long last = 0; // The last time the file was checked for changes long position = 0; // position within the file // Open the file while (run && reader == null) { try { reader = new RandomAccessFile(file, RAF_MODE); } catch (FileNotFoundException e) { listener.fileNotFound(); } if (reader == null) { try { Thread.sleep(delayMillis); } catch (InterruptedException e) { } } else { // The current position in the file // position = (startOffset > file.length()) ? file.length() : startOffset; if (startOffset == -1) { position = file.length(); } else { position = startOffset; } last = System.currentTimeMillis(); reader.seek(position); } } while (run) { boolean newer = FileUtils.isFileNewer(file, last); // IO-279, must be done first // Check the file length to see if it was rotated long length = file.length(); if (length < position) { // File was rotated listener.fileRotated(); // Reopen the reader after rotation try { // Ensure that the old file is closed iff we re-open it successfully RandomAccessFile save = reader; reader = new RandomAccessFile(file, RAF_MODE); position = 0; // close old file explicitly rather than relying on GC picking up previous RAF IOUtils.closeQuietly(save); } catch (FileNotFoundException e) { // in this case we continue to use the previous reader and position values listener.fileNotFound(); } continue; } else { // File was not rotated // See if the file needs to be read again if (length > position) { // The file has more content than it did last time position = readLines(reader); last = System.currentTimeMillis(); } else if (newer) { /* * This can happen if the file is truncated or overwritten with the exact same length of * information. In cases like this, the file position needs to be reset */ position = 0; reader.seek(position); // cannot be null here // Now we can read new lines position = readLines(reader); last = System.currentTimeMillis(); } else { Thread.sleep(DEFAULT_DELAY_MILLIS); } } } } catch (Exception e) { listener.handle(e); } finally { IOUtils.closeQuietly(reader); } }
From source file:com.evolveum.midpoint.tools.gui.PropertiesGenerator.java
private List<File> reloadProperties(File parent, List<String> folders, boolean recursive, Locale locale, File target) throws IOException { List<File> actualTargetFiles = new ArrayList<File>(); Properties baseProperties;//w ww .j av a2s .c om Properties targetProperties; for (String path : folders) { File realFolder = new File(parent, path); Reader baseReader = null; Reader targetReader = null; Collection<File> files = FileUtils.listFiles(realFolder, new String[] { "properties" }, recursive); for (File file : files) { try { File targetPropertiesFile = createTargetFile(file, target, locale); actualTargetFiles.add(targetPropertiesFile); if (targetPropertiesFile.exists() && !FileUtils.isFileNewer(file, targetPropertiesFile)) { System.out.println("File was not modified: " + targetPropertiesFile.getName()); continue; } baseReader = new InputStreamReader(new FileInputStream(file), ENCODING); baseProperties = new Properties(); baseProperties.load(baseReader); targetProperties = new SortedProperties(); if (targetPropertiesFile.exists() && targetPropertiesFile.canRead()) { targetReader = new InputStreamReader(new FileInputStream(targetPropertiesFile), ENCODING); targetProperties.load(targetReader); } PropertiesStatistics stats = mergeProperties(baseProperties, targetProperties); this.stats.increment(stats); backupExistingAndSaveNewProperties(targetProperties, targetPropertiesFile); System.out.println(targetPropertiesFile.getName() + ": " + stats); } finally { IOUtils.closeQuietly(baseReader); IOUtils.closeQuietly(targetReader); } } } return actualTargetFiles; }
From source file:dbseer.comp.process.live.LogTailer.java
@Override public void run() { RandomAccessFile reader = null; try {//from w ww . j a v a2 s . c om long last = 0; // The last time the file was checked for changes long position = 0; // position within the file // Open the file while (run && reader == null) { try { reader = new RandomAccessFile(file, RAF_MODE); } catch (FileNotFoundException e) { listener.fileNotFound(); } if (reader == null) { try { Thread.sleep(delayMillis); } catch (InterruptedException e) { } } else { // The current position in the file // position = (startOffset > file.length()) ? file.length() : startOffset; if (startOffset == -1) { position = file.length(); } else { position = startOffset; } last = System.currentTimeMillis(); reader.seek(position); } } while (run) { boolean newer = FileUtils.isFileNewer(file, last); // IO-279, must be done first // Check the file length to see if it was rotated long length = file.length(); if (length < position) { // File was rotated listener.fileRotated(); // Reopen the reader after rotation try { // Ensure that the old file is closed iff we re-open it successfully RandomAccessFile save = reader; reader = new RandomAccessFile(file, RAF_MODE); position = 0; // close old file explicitly rather than relying on GC picking up previous RAF IOUtils.closeQuietly(save); } catch (FileNotFoundException e) { // in this case we continue to use the previous reader and position values listener.fileNotFound(); } continue; } else { // File was not rotated // See if the file needs to be read again if (length > position) { // The file has more content than it did last time position = readLines(reader); last = System.currentTimeMillis(); } else if (newer) { /* * This can happen if the file is truncated or overwritten with the exact same length of * information. In cases like this, the file position needs to be reset */ if (resetFilePositionIfOverwrittenWithTheSameLength) { position = 0; reader.seek(position); // cannot be null here // Now we can read new lines position = readLines(reader); last = System.currentTimeMillis(); } } else { Thread.sleep(DEFAULT_DELAY_MILLIS); } } } } catch (Exception e) { listener.handle(e); } finally { IOUtils.closeQuietly(reader); } }