@@ -86,11 +86,25 @@ public FileUtils() {
8686 */
8787 public static final long ONE_KB = 1024 ;
8888
89+ /**
90+ * The number of bytes in a kilobyte.
91+ *
92+ * @since 2.4
93+ */
94+ public static final BigInteger ONE_KB_BI = BigInteger .valueOf (ONE_KB );
95+
8996 /**
9097 * The number of bytes in a megabyte.
9198 */
9299 public static final long ONE_MB = ONE_KB * ONE_KB ;
93100
101+ /**
102+ * The number of bytes in a megabyte.
103+ *
104+ * @since 2.4
105+ */
106+ public static final BigInteger ONE_MB_BI = ONE_KB_BI .multiply (ONE_KB_BI );
107+
94108 /**
95109 * The file copy buffer size (30 MB)
96110 */
@@ -101,21 +115,49 @@ public FileUtils() {
101115 */
102116 public static final long ONE_GB = ONE_KB * ONE_MB ;
103117
118+ /**
119+ * The number of bytes in a gigabyte.
120+ *
121+ * @since 2.4
122+ */
123+ public static final BigInteger ONE_GB_BI = ONE_KB_BI .multiply (ONE_MB_BI );
124+
104125 /**
105126 * The number of bytes in a terabyte.
106127 */
107128 public static final long ONE_TB = ONE_KB * ONE_GB ;
108129
130+ /**
131+ * The number of bytes in a terabyte.
132+ *
133+ * @since 2.4
134+ */
135+ public static final BigInteger ONE_TB_BI = ONE_KB_BI .multiply (ONE_GB_BI );
136+
109137 /**
110138 * The number of bytes in a petabyte.
111139 */
112140 public static final long ONE_PB = ONE_KB * ONE_TB ;
113141
142+ /**
143+ * The number of bytes in a petabyte.
144+ *
145+ * @since 2.4
146+ */
147+ public static final BigInteger ONE_PB_BI = ONE_KB_BI .multiply (ONE_TB_BI );
148+
114149 /**
115150 * The number of bytes in an exabyte.
116151 */
117152 public static final long ONE_EB = ONE_KB * ONE_PB ;
118153
154+ /**
155+ * The number of bytes in an exabyte.
156+ *
157+ * @since 2.4
158+ */
159+ public static final BigInteger ONE_EB_BI = ONE_KB_BI .multiply (ONE_PB_BI );
160+
119161 /**
120162 * The number of bytes in a zettabyte.
121163 */
@@ -326,39 +368,63 @@ public static FileOutputStream openOutputStream(File file, boolean append) throw
326368
327369 //-----------------------------------------------------------------------
328370 /**
329- * Returns a human-readable version of the file size, where the input
330- * represents a specific number of bytes.
331- *
332- * If the size is over 1GB, the size is returned as the number of whole GB,
333- * i.e. the size is rounded down to the nearest GB boundary.
334- *
371+ * Returns a human-readable version of the file size, where the input represents a specific number of bytes.
372+ * <p>
373+ * 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
374+ * nearest GB boundary.
375+ * </p>
376+ * <p>
335377 * Similarly for the 1MB and 1KB boundaries.
336- *
337- * @param size the number of bytes
338- * @return a human-readable display value (includes units - GB, MB, KB or bytes)
378+ * </p>
379+ *
380+ * @param size
381+ * the number of bytes
382+ * @return a human-readable display value (includes units - EB, PB, TB, GB, MB, KB or bytes)
383+ * @see <a href="https://issues.apache.org/jira/browse/IO-226">IO-226 - should the rounding be changed?</a>
384+ * @since 2.4
339385 */
340386 // See https://issues.apache.org/jira/browse/IO-226 - should the rounding be changed?
341- public static String byteCountToDisplaySize (long size ) {
387+ public static String byteCountToDisplaySize (BigInteger size ) {
342388 String displaySize ;
343389
344- if (size / ONE_EB > 0 ) {
345- displaySize = String .valueOf (size / ONE_EB ) + " EB" ;
346- } else if (size / ONE_PB > 0 ) {
347- displaySize = String .valueOf (size / ONE_PB ) + " PB" ;
348- } else if (size / ONE_TB > 0 ) {
349- displaySize = String .valueOf (size / ONE_TB ) + " TB" ;
350- } else if (size / ONE_GB > 0 ) {
351- displaySize = String .valueOf (size / ONE_GB ) + " GB" ;
352- } else if (size / ONE_MB > 0 ) {
353- displaySize = String .valueOf (size / ONE_MB ) + " MB" ;
354- } else if (size / ONE_KB > 0 ) {
355- displaySize = String .valueOf (size / ONE_KB ) + " KB" ;
390+ if (size . divide ( ONE_EB_BI ). compareTo ( BigInteger . ZERO ) > 0 ) {
391+ displaySize = String .valueOf (size . divide ( ONE_EB_BI ) ) + " EB" ;
392+ } else if (size . divide ( ONE_PB_BI ). compareTo ( BigInteger . ZERO ) > 0 ) {
393+ displaySize = String .valueOf (size . divide ( ONE_PB_BI ) ) + " PB" ;
394+ } else if (size . divide ( ONE_TB_BI ). compareTo ( BigInteger . ZERO ) > 0 ) {
395+ displaySize = String .valueOf (size . divide ( ONE_TB_BI ) ) + " TB" ;
396+ } else if (size . divide ( ONE_GB_BI ). compareTo ( BigInteger . ZERO ) > 0 ) {
397+ displaySize = String .valueOf (size . divide ( ONE_GB_BI ) ) + " GB" ;
398+ } else if (size . divide ( ONE_MB_BI ). compareTo ( BigInteger . ZERO ) > 0 ) {
399+ displaySize = String .valueOf (size . divide ( ONE_MB_BI ) ) + " MB" ;
400+ } else if (size . divide ( ONE_KB_BI ). compareTo ( BigInteger . ZERO ) > 0 ) {
401+ displaySize = String .valueOf (size . divide ( ONE_KB_BI ) ) + " KB" ;
356402 } else {
357403 displaySize = String .valueOf (size ) + " bytes" ;
358404 }
359405 return displaySize ;
360406 }
361407
408+ /**
409+ * Returns a human-readable version of the file size, where the input represents a specific number of bytes.
410+ * <p>
411+ * 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
412+ * nearest GB boundary.
413+ * </p>
414+ * <p>
415+ * Similarly for the 1MB and 1KB boundaries.
416+ * </p>
417+ *
418+ * @param size
419+ * the number of bytes
420+ * @return a human-readable display value (includes units - EB, PB, TB, GB, MB, KB or bytes)
421+ * @see <a href="https://issues.apache.org/jira/browse/IO-226">IO-226 - should the rounding be changed?</a>
422+ */
423+ // See https://issues.apache.org/jira/browse/IO-226 - should the rounding be changed?
424+ public static String byteCountToDisplaySize (long size ) {
425+ return byteCountToDisplaySize (BigInteger .valueOf (size ));
426+ }
427+
362428 //-----------------------------------------------------------------------
363429 /**
364430 * Implements the same behaviour as the "touch" utility on Unix. It creates
0 commit comments