/** * Checks to see if the last modification of the file matches cutoff * favorably. * <p> * If last modification time equals cutoff and newer files are required, * file <b>IS NOT</b> selected. * If last modification time equals cutoff and older files are required, * file <b>IS</b> selected. * * @param file the File to check * @return true if the filename matches */ @Override public boolean accept(final File file) { final boolean newer = FileUtils.isFileNewer(file, cutoff); return acceptOlder ? !newer : newer; }
/** * Checks to see if the last modification of the file matches cutoff * favorably. * <p> * If last modification time equals cutoff and newer files are required, * file <b>IS NOT</b> selected. * If last modification time equals cutoff and older files are required, * file <b>IS</b> selected. * * @param file the File to check * @return true if the filename matches */ public boolean accept(File file) { boolean newer = FileUtils.isFileNewer(file, cutoff); return acceptOlder ? !newer : newer; }
/** * Tests if the specified <code>File</code> is newer than the specified * <code>Date</code>. * * @param file the <code>File</code> of which the modification date * must be compared, must not be {@code null} * @param date the date reference, must not be {@code null} * @return true if the <code>File</code> exists and has been modified * after the given <code>Date</code>. * @throws IllegalArgumentException if the file is {@code null} * @throws IllegalArgumentException if the date is {@code null} */ public static boolean isFileNewer(final File file, final Date date) { if (date == null) { throw new IllegalArgumentException("No specified date"); } return isFileNewer(file, date.getTime()); }
/** * Tests if the specified <code>File</code> is newer than the reference * <code>File</code>. * * @param file the <code>File</code> of which the modification date must * be compared, must not be {@code null} * @param reference the <code>File</code> of which the modification date * is used, must not be {@code null} * @return true if the <code>File</code> exists and has been modified more * recently than the reference <code>File</code> * @throws IllegalArgumentException if the file is {@code null} * @throws IllegalArgumentException if the reference file is {@code null} or doesn't exist */ public static boolean isFileNewer(final File file, final File reference) { if (reference == null) { throw new IllegalArgumentException("No specified reference file"); } if (!reference.exists()) { throw new IllegalArgumentException("The reference file '" + reference + "' doesn't exist"); } return isFileNewer(file, reference.lastModified()); }
/** * Tests if the specified <code>File</code> is newer than the specified * <code>Date</code>. * * @param file the <code>File</code> of which the modification date * must be compared, must not be <code>null</code> * @param date the date reference, must not be <code>null</code> * @return true if the <code>File</code> exists and has been modified * after the given <code>Date</code>. * @throws IllegalArgumentException if the file is <code>null</code> * @throws IllegalArgumentException if the date is <code>null</code> */ public static boolean isFileNewer(File file, Date date) { if (date == null) { throw new IllegalArgumentException("No specified date"); } return isFileNewer(file, date.getTime()); }
/** * Tests if the specified <code>File</code> is newer than the reference * <code>File</code>. * * @param file the <code>File</code> of which the modification date must * be compared, must not be <code>null</code> * @param reference the <code>File</code> of which the modification date * is used, must not be <code>null</code> * @return true if the <code>File</code> exists and has been modified more * recently than the reference <code>File</code> * @throws IllegalArgumentException if the file is <code>null</code> * @throws IllegalArgumentException if the reference file is <code>null</code> or doesn't exist */ public static boolean isFileNewer(File file, File reference) { if (reference == null) { throw new IllegalArgumentException("No specified reference file"); } if (!reference.exists()) { throw new IllegalArgumentException("The reference file '" + file + "' doesn't exist"); } return isFileNewer(file, reference.lastModified()); }
/** * Deletes files in the given directory which are older than 2 hours. * * @param dir the directory to clean up */ private static void cleanUpOldFiles(File dir) { long cutoffTimestamp = System.currentTimeMillis() - (MAX_FILE_AGE_HOURS * Constants.HOUR_MS); Arrays.asList(dir.listFiles()).stream() .filter(file -> !FileUtils.isFileNewer(file, cutoffTimestamp)) .forEach(file -> delete(file)); }
/** * Tests the <code>isFileNewer(File, long)</code> method without specifying a <code>File</code>. * <br> * The test is successful if the method throws an <code>IllegalArgumentException</code>. */ @Test(expected = IllegalArgumentException.class) public void testIsFileNewerNoFile() { FileUtils.isFileNewer(null,0); fail("File not specified"); }
/** * Tests the <code>isFileNewer(File, Date)</code> method without specifying a <code>Date</code>. * <br> * The test is successful if the method throws an <code>IllegalArgumentException</code>. */ @Test(expected = IllegalArgumentException.class) public void testIsFileNewerNoDate() { FileUtils.isFileNewer(m_testFile1, (Date) null); fail("Date not specified"); }
/** * Tests the <code>isFileNewer(File, File)</code> method without specifying a reference <code>File</code>. * <br> * The test is successful if the method throws an <code>IllegalArgumentException</code>. */ @Test(expected = IllegalArgumentException.class) public void testIsFileNewerNoFileReference() { FileUtils.isFileNewer(m_testFile1, (File) null); fail("Reference file not specified"); } }
final boolean newer = FileUtils.isFileNewer(file, last); // IO-279, must be done first
assertEquals(description + " - time", wantedResult, FileUtils.isFileNewer(file, time)); assertEquals(description + " - date", wantedResult, FileUtils.isFileNewer(file, new Date(time))); assertEquals(description + " - file", wantedResult, FileUtils.isFileNewer(file, temporaryFile));
assertFalse("Old File - Newer - File", FileUtils.isFileNewer(oldFile, reference)); assertFalse("Old File - Newer - Date", FileUtils.isFileNewer(oldFile, date)); assertFalse("Old File - Newer - Mili", FileUtils.isFileNewer(oldFile, now)); assertTrue("New File - Newer - File", FileUtils.isFileNewer(newFile, reference)); assertTrue("New File - Newer - Date", FileUtils.isFileNewer(newFile, date)); assertTrue("New File - Newer - Mili", FileUtils.isFileNewer(newFile, now)); assertFalse("Invalid - Newer - File", FileUtils.isFileNewer(invalidFile, reference)); final String invalidFileName = invalidFile.getName(); try { FileUtils.isFileNewer(newFile, invalidFile); fail("Should have cause IllegalArgumentException"); } catch (final IllegalArgumentException iae) { FileUtils.isFileNewer(null, now); fail("Newer Null, expected IllegalArgumentExcepion"); } catch (final IllegalArgumentException expected) { FileUtils.isFileNewer(oldFile, (File) null); fail("Newer Null reference, expected IllegalArgumentExcepion"); } catch (final IllegalArgumentException ignore) { FileUtils.isFileNewer(oldFile, invalidFile); fail("Newer invalid reference, expected IllegalArgumentExcepion"); } catch (final IllegalArgumentException ignore) { FileUtils.isFileNewer(oldFile, (Date) null); fail("Newer Null date, expected IllegalArgumentExcepion"); } catch (final IllegalArgumentException ignore) {
public int compare(File file1, File file2) { if (org.apache.commons.io.FileUtils.isFileNewer(file1, file2)) { return 1; } else { return -1; } } });
/** * Checks to see if the last modification of the file matches cutoff * favorably. * <p> * If last modification time equals cutoff and newer files are required, * file <b>IS NOT</b> selected. * If last modification time equals cutoff and older files are required, * file <b>IS</b> selected. * * @param file the File to check * @return true if the filename matches */ @Override public boolean accept(final File file) { final boolean newer = FileUtils.isFileNewer(file, cutoff); return acceptOlder ? !newer : newer; }
/** * Checks to see if the last modification of the file matches cutoff * favorably. * <p> * If last modification time equals cutoff and newer files are required, * file <b>IS NOT</b> selected. * If last modification time equals cutoff and older files are required, * file <b>IS</b> selected. * * @param file the File to check * @return true if the filename matches */ @Override public boolean accept(final File file) { final boolean newer = FileUtils.isFileNewer(file, cutoff); return acceptOlder ? !newer : newer; }
/** * Checks to see if the last modification of the file matches cutoff * favorably. * <p> * If last modification time equals cutoff and newer files are required, * file <b>IS NOT</b> selected. * If last modification time equals cutoff and older files are required, * file <b>IS</b> selected. * * @param file the File to check * @return true if the filename matches */ public boolean accept(File file) { boolean newer = FileUtils.isFileNewer(file, cutoff); return acceptOlder ? !newer : newer; }
public int compare(File file1, File file2) { if (file1.lastModified() == file2.lastModified()) { return 0; } else { return FileUtils.isFileNewer(file1, file2) ? -1 : 1; } } }
@Override public boolean accept(File file) { long timeMillis = System.currentTimeMillis() - cutoff; if(after) { return FileUtils.isFileNewer(file, timeMillis); } else { return FileUtils.isFileOlder(file, timeMillis); } }
public static void detectChanges(List<Resource> fileResources) throws IOException { boolean hasChanged = false; for (Resource res : fileResources) { if (FileUtils.isFileNewer(res.getFile(), lastLoading)) { hasChanged = true; break; } } if (hasChanged) { load(fileResources); } }