Add FileUtils.lastModifiedFileTime(File).
Add AgeFileFilter.AgeFileFilter(Instant).
MODIFY
src/changes/changes.xml
src/changes/changes.xml
@@ -154,8 +154,12 @@ The <action> type attribute can be add,update,fix,remove.
Add PathUtils.isNewer(Path, Instant, LinkOption...).
</action>
<action dev="ggregory" type="add" due-to="Gary Gregory">
+ Add AgeFileFilter.AgeFileFilter(Instant).
Add AgeFileFilter.AgeFileFilter(Instant, boolean).
</action>
+ <action dev="ggregory" type="add" due-to="Gary Gregory">
+ Add FileUtils.lastModifiedFileTime(File).
+ </action>
<!-- UPDATE -->
<action dev="ggregory" type="update" due-to="Dependabot">
Bump Maven Javadoc plugin from 3.2.0 to 3.3.0.

MODIFY
src/main/java/org/apache/commons/io/FileUtils.java
src/main/java/org/apache/commons/io/FileUtils.java
import java.nio.file.NotDirectoryException;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
+import java.nio.file.attribute.FileTime;
import java.time.Instant;
import java.time.LocalTime;
import java.time.ZoneId;
@@ -1974,7 +1975,28 @@ public static long lastModified(final File file) throws IOException {
// https://bugs.openjdk.java.net/browse/JDK-8177809
// File.lastModified() is losing milliseconds (always ends in 000)
// This bug is in OpenJDK 8 and 9, and fixed in 10.
- return Files.getLastModifiedTime(Objects.requireNonNull(file.toPath(), "file")).toMillis();
+ return lastModifiedFileTime(file).toMillis();
+ }
+
+ /**
+ * Returns the last modification {@link FileTime} via
+ * {@link java.nio.file.Files#getLastModifiedTime(Path, LinkOption...)}.
+ * <p>
+ * Use this method to avoid issues with {@link File#lastModified()} like
+ * <a href="https://bugs.openjdk.java.net/browse/JDK-8177809">JDK-8177809</a> where {@link File#lastModified()} is
+ * losing milliseconds (always ends in 000). This bug exists in OpenJDK 8 and 9, and is fixed in 10.
+ * </p>
+ *
+ * @param file The File to query.
+ * @return See {@link java.nio.file.Files#getLastModifiedTime(Path, LinkOption...)}.
+ * @throws IOException if an I/O error occurs.
+ * @since 2.12.0
+ */
+ public static FileTime lastModifiedFileTime(final File file) throws IOException {
+ // https://bugs.openjdk.java.net/browse/JDK-8177809
+ // File.lastModified() is losing milliseconds (always ends in 000)
+ // This bug is in OpenJDK 8 and 9, and fixed in 10.
+ return Files.getLastModifiedTime(Objects.requireNonNull(file.toPath(), "file"));
}
/**

MODIFY
src/main/java/org/apache/commons/io/filefilter/AgeFileFilter.java
src/main/java/org/apache/commons/io/filefilter/AgeFileFilter.java
@@ -100,7 +100,7 @@ public AgeFileFilter(final Date cutoffDate) {
* cutoff).
*/
public AgeFileFilter(final Date cutoffDate, final boolean acceptOlder) {
- this(cutoffDate.getTime(), acceptOlder);
+ this(cutoffDate.toInstant(), acceptOlder);
}
/**
@@ -125,6 +125,17 @@ public AgeFileFilter(final File cutoffReference, final boolean acceptOlder) {
this(FileUtils.lastModifiedUnchecked(cutoffReference), acceptOlder);
}
+ /**
+ * Constructs a new age file filter for files equal to or older than a certain cutoff
+ *
+ * @param cutoffInstant The cutoff time threshold measured in milliseconds since the epoch (00:00:00 GMT, January 1,
+ * 1970).
+ * @since 2.12.0
+ */
+ public AgeFileFilter(final Instant cutoffInstant) {
+ this(cutoffInstant, true);
+ }
+
/**
* Constructs a new age file filter for files on any one side of a certain cutoff.
*
@@ -146,7 +157,7 @@ public AgeFileFilter(final Instant cutoffInstant, final boolean acceptOlder) {
* 1970).
*/
public AgeFileFilter(final long cutoffMillis) {
- this(cutoffMillis, true);
+ this(Instant.ofEpochMilli(cutoffMillis), true);
}
/**

Add FileUtils.lastModifiedFileTime(File).

Add AgeFileFilter.AgeFileFilter(Instant).