@@ -266,6 +266,26 @@ public static String byteCountToDisplaySize(final long size) {
266266 return byteCountToDisplaySize (BigInteger .valueOf (size ));
267267 }
268268
269+ /**
270+ * Returns a human-readable version of the file size, where the input represents a specific number of bytes.
271+ * <p>
272+ * If the size is over 1GB, the size is returned as the number of whole GB, i.e. the size is rounded down to the
273+ * nearest GB boundary.
274+ * </p>
275+ * <p>
276+ * Similarly for the 1MB and 1KB boundaries.
277+ * </p>
278+ *
279+ * @param size the number of bytes
280+ * @return a human-readable display value (includes units - EB, PB, TB, GB, MB, KB or bytes)
281+ * @see <a href="https://issues.apache.org/jira/browse/IO-226">IO-226 - should the rounding be changed?</a>
282+ * @since 2.12.0
283+ */
284+ // See https://issues.apache.org/jira/browse/IO-226 - should the rounding be changed?
285+ public static String byteCountToDisplaySize (final Number size ) {
286+ return byteCountToDisplaySize (size .longValue ());
287+ }
288+
269289 /**
270290 * Computes the checksum of a file using the specified checksum object. Multiple files may be checked using one
271291 * {@code Checksum} instance if desired simply by reusing the same checksum object. For example:
@@ -1560,22 +1580,6 @@ public static boolean isFileNewer(final File file, final ChronoLocalDate chronoL
15601580 return isFileNewer (file , chronoLocalDate , LocalTime .now ());
15611581 }
15621582
1563- /**
1564- * Tests if the specified {@code File} is newer than the specified {@code FileTime}.
1565- *
1566- * @param file the {@code File} of which the modification date must be compared.
1567- * @param fileTime the file time reference.
1568- * @return true if the {@code File} exists and has been modified after the given {@code FileTime}.
1569- * @throws IOException if an I/O error occurs.
1570- * @throws NullPointerException if the file or local date is {@code null}.
1571- *
1572- * @since 2.12.0
1573- */
1574- public static boolean isFileNewer (final File file , final FileTime fileTime ) throws IOException {
1575- Objects .requireNonNull (file , "file" );
1576- return PathUtils .isNewer (file .toPath (), fileTime );
1577- }
1578-
15791583 /**
15801584 * Tests if the specified {@code File} is newer than the specified {@code ChronoLocalDate}
15811585 * at the specified time.
@@ -1695,6 +1699,22 @@ public static boolean isFileNewer(final File file, final File reference) {
16951699 }
16961700 }
16971701
1702+ /**
1703+ * Tests if the specified {@code File} is newer than the specified {@code FileTime}.
1704+ *
1705+ * @param file the {@code File} of which the modification date must be compared.
1706+ * @param fileTime the file time reference.
1707+ * @return true if the {@code File} exists and has been modified after the given {@code FileTime}.
1708+ * @throws IOException if an I/O error occurs.
1709+ * @throws NullPointerException if the file or local date is {@code null}.
1710+ *
1711+ * @since 2.12.0
1712+ */
1713+ public static boolean isFileNewer (final File file , final FileTime fileTime ) throws IOException {
1714+ Objects .requireNonNull (file , "file" );
1715+ return PathUtils .isNewer (file .toPath (), fileTime );
1716+ }
1717+
16981718 /**
16991719 * Tests if the specified {@code File} is newer than the specified {@code Instant}.
17001720 *
@@ -1864,7 +1884,28 @@ public static boolean isFileOlder(final File file, final Date date) {
18641884 */
18651885 public static boolean isFileOlder (final File file , final File reference ) {
18661886 requireExists (reference , "reference" );
1867- return isFileOlder (file , lastModifiedUnchecked (reference ));
1887+ try {
1888+ return PathUtils .isOlder (file .toPath (), reference .toPath ());
1889+ } catch (final IOException e ) {
1890+ // TODO Update method signature
1891+ throw new UncheckedIOException (e );
1892+ }
1893+ }
1894+
1895+ /**
1896+ * Tests if the specified {@code File} is older than the specified {@code FileTime}.
1897+ *
1898+ * @param file the {@code File} of which the modification date must be compared.
1899+ * @param fileTime the file time reference.
1900+ * @return true if the {@code File} exists and has been modified before the given {@code FileTime}.
1901+ * @throws IOException if an I/O error occurs.
1902+ * @throws NullPointerException if the file or local date is {@code null}.
1903+ *
1904+ * @since 2.12.0
1905+ */
1906+ public static boolean isFileOlder (final File file , final FileTime fileTime ) throws IOException {
1907+ Objects .requireNonNull (file , "file" );
1908+ return PathUtils .isOlder (file .toPath (), fileTime );
18681909 }
18691910
18701911 /**
@@ -1878,7 +1919,12 @@ public static boolean isFileOlder(final File file, final File reference) {
18781919 */
18791920 public static boolean isFileOlder (final File file , final Instant instant ) {
18801921 Objects .requireNonNull (instant , "instant" );
1881- return isFileOlder (file , instant .toEpochMilli ());
1922+ try {
1923+ return PathUtils .isOlder (file .toPath (), instant );
1924+ } catch (final IOException e ) {
1925+ // TODO Update method signature
1926+ throw new UncheckedIOException (e );
1927+ }
18821928 }
18831929
18841930 /**
@@ -1892,7 +1938,12 @@ public static boolean isFileOlder(final File file, final Instant instant) {
18921938 */
18931939 public static boolean isFileOlder (final File file , final long timeMillis ) {
18941940 Objects .requireNonNull (file , "file" );
1895- return file .exists () && lastModifiedUnchecked (file ) < timeMillis ;
1941+ try {
1942+ return PathUtils .isOlder (file .toPath (), timeMillis );
1943+ } catch (final IOException e ) {
1944+ // TODO Update method signature
1945+ throw new UncheckedIOException (e );
1946+ }
18961947 }
18971948
18981949 /**
@@ -2008,6 +2059,9 @@ public static Iterator<File> iterateFilesAndDirs(final File directory, final IOF
20082059 * Returns the last modification time in milliseconds via
20092060 * {@link java.nio.file.Files#getLastModifiedTime(Path, LinkOption...)}.
20102061 * <p>
2062+ * For the best precision, use {@link #lastModifiedFileTime(File)}.
2063+ * </p>
2064+ * <p>
20112065 * Use this method to avoid issues with {@link File#lastModified()} like
20122066 * <a href="https://bugs.openjdk.java.net/browse/JDK-8177809">JDK-8177809</a> where {@link File#lastModified()} is
20132067 * losing milliseconds (always ends in 000). This bug exists in OpenJDK 8 and 9, and is fixed in 10.
@@ -2050,6 +2104,9 @@ public static FileTime lastModifiedFileTime(final File file) throws IOException
20502104 * Returns the last modification time in milliseconds via
20512105 * {@link java.nio.file.Files#getLastModifiedTime(Path, LinkOption...)}.
20522106 * <p>
2107+ * For the best precision, use {@link #lastModifiedFileTime(File)}.
2108+ * </p>
2109+ * <p>
20532110 * Use this method to avoid issues with {@link File#lastModified()} like
20542111 * <a href="https://bugs.openjdk.java.net/browse/JDK-8177809">JDK-8177809</a> where {@link File#lastModified()} is
20552112 * losing milliseconds (always ends in 000). This bug exists in OpenJDK 8 and 9, and is fixed in 10.
0 commit comments