This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-io.git
The following commit(s) were added to refs/heads/master by this push:
new e53dddc92 `FileUtils#byteCountToDisplaySize` supports Zettabyte,
Yottabyte, Ronnabyte and Quettabyte (#763)
e53dddc92 is described below
commit e53dddc9233341be456463d343ccebd2d7785337
Author: strangelookingnerd
<[email protected]>
AuthorDate: Mon Jul 21 16:35:48 2025 +0200
`FileUtils#byteCountToDisplaySize` supports Zettabyte, Yottabyte, Ronnabyte
and Quettabyte (#763)
* FileUtils#byteCountToDisplaySize supports Zettabyte, Yottabyte, Ronnabyte
and Quettabyte
* Update javadoc to reflect all supported units
* Add missing Javadoc since tags
* Remove bad import
---------
Co-authored-by: Gary Gregory <[email protected]>
---
src/main/java/org/apache/commons/io/FileUtils.java | 28 +++++++++++++++++++---
.../java/org/apache/commons/io/FileUtilsTest.java | 8 +++++++
2 files changed, 33 insertions(+), 3 deletions(-)
diff --git a/src/main/java/org/apache/commons/io/FileUtils.java
b/src/main/java/org/apache/commons/io/FileUtils.java
index ffd59f92a..cc17576b6 100644
--- a/src/main/java/org/apache/commons/io/FileUtils.java
+++ b/src/main/java/org/apache/commons/io/FileUtils.java
@@ -194,13 +194,27 @@ public class FileUtils {
/**
* The number of bytes in a zettabyte.
*/
- public static final BigInteger ONE_ZB =
BigInteger.valueOf(ONE_KB).multiply(BigInteger.valueOf(ONE_EB));
+ public static final BigInteger ONE_ZB = ONE_KB_BI.multiply(ONE_EB_BI);
/**
* The number of bytes in a yottabyte.
*/
public static final BigInteger ONE_YB = ONE_KB_BI.multiply(ONE_ZB);
+ /**
+ * The number of bytes in a ronnabyte.
+ *
+ * @since 2.21.0
+ */
+ public static final BigInteger ONE_RB = ONE_KB_BI.multiply(ONE_YB);
+
+ /**
+ * The number of bytes in a quettabyte.
+ *
+ * @since 2.21.0
+ */
+ public static final BigInteger ONE_QB = ONE_KB_BI.multiply(ONE_RB);
+
/**
* An empty array of type {@link File}.
*/
@@ -217,7 +231,7 @@ public class FileUtils {
* </p>
*
* @param size the number of bytes
- * @return a human-readable display value (includes units - EB, PB, TB,
GB, MB, KB or bytes)
+ * @return a human-readable display value (includes units - QB, RB, YB,
ZB, EB, PB, TB, GB, MB, KB or bytes)
* @throws NullPointerException if the given {@link BigInteger} is {@code
null}.
* @see <a href="https://issues.apache.org/jira/browse/IO-226">IO-226 -
should the rounding be changed?</a>
* @since 2.4
@@ -227,7 +241,15 @@ public static String byteCountToDisplaySize(final
BigInteger size) {
Objects.requireNonNull(size, "size");
final String displaySize;
- if (size.divide(ONE_EB_BI).compareTo(BigInteger.ZERO) > 0) {
+ if (size.divide(ONE_QB).compareTo(BigInteger.ZERO) > 0) {
+ displaySize = size.divide(ONE_QB) + " QB";
+ } else if (size.divide(ONE_RB).compareTo(BigInteger.ZERO) > 0) {
+ displaySize = size.divide(ONE_RB) + " RB";
+ } else if (size.divide(ONE_YB).compareTo(BigInteger.ZERO) > 0) {
+ displaySize = size.divide(ONE_YB) + " YB";
+ } else if (size.divide(ONE_ZB).compareTo(BigInteger.ZERO) > 0) {
+ displaySize = size.divide(ONE_ZB) + " ZB";
+ } else if (size.divide(ONE_EB_BI).compareTo(BigInteger.ZERO) > 0) {
displaySize = size.divide(ONE_EB_BI) + " EB";
} else if (size.divide(ONE_PB_BI).compareTo(BigInteger.ZERO) > 0) {
displaySize = size.divide(ONE_PB_BI) + " PB";
diff --git a/src/test/java/org/apache/commons/io/FileUtilsTest.java
b/src/test/java/org/apache/commons/io/FileUtilsTest.java
index cf62cf2c1..dc501ee08 100644
--- a/src/test/java/org/apache/commons/io/FileUtilsTest.java
+++ b/src/test/java/org/apache/commons/io/FileUtilsTest.java
@@ -370,6 +370,10 @@ void testByteCountToDisplaySizeBigInteger() {
final BigInteger TB1 = GB1.multiply(KB1);
final BigInteger PB1 = TB1.multiply(KB1);
final BigInteger EB1 = PB1.multiply(KB1);
+ final BigInteger ZB1 = EB1.multiply(KB1);
+ final BigInteger YB1 = ZB1.multiply(KB1);
+ final BigInteger RB1 = YB1.multiply(KB1);
+ final BigInteger QB1 = RB1.multiply(KB1);
assertEquals("0 bytes",
FileUtils.byteCountToDisplaySize(BigInteger.ZERO));
assertEquals("1 bytes",
FileUtils.byteCountToDisplaySize(BigInteger.ONE));
assertEquals("1023 bytes", FileUtils.byteCountToDisplaySize(b1023));
@@ -386,6 +390,10 @@ void testByteCountToDisplaySizeBigInteger() {
assertEquals("1 TB", FileUtils.byteCountToDisplaySize(TB1));
assertEquals("1 PB", FileUtils.byteCountToDisplaySize(PB1));
assertEquals("1 EB", FileUtils.byteCountToDisplaySize(EB1));
+ assertEquals("1 ZB", FileUtils.byteCountToDisplaySize(ZB1));
+ assertEquals("1 YB", FileUtils.byteCountToDisplaySize(YB1));
+ assertEquals("1 RB", FileUtils.byteCountToDisplaySize(RB1));
+ assertEquals("1 QB", FileUtils.byteCountToDisplaySize(QB1));
assertEquals("7 EB", FileUtils.byteCountToDisplaySize(Long.MAX_VALUE));
// Other MAX_VALUEs
assertEquals("63 KB",
FileUtils.byteCountToDisplaySize(BigInteger.valueOf(Character.MAX_VALUE)));