commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1153952 - in /commons/proper/io/trunk/src: main/java/org/apache/commons/io/FileUtils.java test/java/org/apache/commons/io/FileUtilsTestCase.java
Date Thu, 04 Aug 2011 17:47:25 GMT
Author: ggregory
Date: Thu Aug  4 17:47:24 2011
New Revision: 1153952

URL: http://svn.apache.org/viewvc?rev=1153952&view=rev
Log:
[IO-226] question with byteCountToDisplaySize(long size). Add more tests. Add commented out
code for processing terabyte, petabyte and exabyte. Add constants for terabyte, petabyte and
exabyte, zettabyte, and yottabyte.

Modified:
    commons/proper/io/trunk/src/main/java/org/apache/commons/io/FileUtils.java
    commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileUtilsTestCase.java

Modified: commons/proper/io/trunk/src/main/java/org/apache/commons/io/FileUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/main/java/org/apache/commons/io/FileUtils.java?rev=1153952&r1=1153951&r2=1153952&view=diff
==============================================================================
--- commons/proper/io/trunk/src/main/java/org/apache/commons/io/FileUtils.java (original)
+++ commons/proper/io/trunk/src/main/java/org/apache/commons/io/FileUtils.java Thu Aug  4
17:47:24 2011
@@ -24,6 +24,7 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.math.BigInteger;
 import java.net.URL;
 import java.net.URLConnection;
 import java.nio.ByteBuffer;
@@ -110,6 +111,31 @@ public class FileUtils {
     public static final long ONE_GB = ONE_KB * ONE_MB;
 
     /**
+     * The number of bytes in a terabyte.
+     */
+    public static final long ONE_TB = ONE_KB * ONE_GB;
+
+    /**
+     * The number of bytes in a petabyte.
+     */
+    public static final long ONE_PB = ONE_KB * ONE_TB;
+
+    /**
+     * The number of bytes in an exabyte.
+     */
+    public static final long ONE_EB = ONE_KB * ONE_PB;
+
+    /**
+     * The number of bytes in a zettabyte.
+     */
+    public static final BigInteger ONE_ZB = BigInteger.valueOf(ONE_KB).multiply(BigInteger.valueOf(ONE_EB));
+
+    /**
+     * The number of bytes in a yottabyte.
+     */
+    public static final BigInteger ONE_YB = ONE_ZB.multiply(BigInteger.valueOf(ONE_EB));
+
+    /**
      * An empty array of type <code>File</code>.
      */
     public static final File[] EMPTY_FILE_ARRAY = new File[0];
@@ -324,6 +350,13 @@ public class FileUtils {
     public static String byteCountToDisplaySize(long size) {
         String displaySize;
 
+//        if (size / ONE_EB > 0) {
+//            displaySize = String.valueOf(size / ONE_EB) + " EB";
+//        } else if (size / ONE_PB > 0) {
+//            displaySize = String.valueOf(size / ONE_PB) + " PB";
+//        } else if (size / ONE_TB > 0) {
+//            displaySize = String.valueOf(size / ONE_TB) + " TB";
+//        } else 
         if (size / ONE_GB > 0) {
             displaySize = String.valueOf(size / ONE_GB) + " GB";
         } else if (size / ONE_MB > 0) {

Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileUtilsTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileUtilsTestCase.java?rev=1153952&r1=1153951&r2=1153952&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileUtilsTestCase.java (original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileUtilsTestCase.java Thu
Aug  4 17:47:24 2011
@@ -311,11 +311,25 @@ public class FileUtilsTestCase extends F
     // byteCountToDisplaySize
     public void testByteCountToDisplaySize() {
         assertEquals(FileUtils.byteCountToDisplaySize(0), "0 bytes");
+        assertEquals(FileUtils.byteCountToDisplaySize(1), "1 bytes");
+        assertEquals(FileUtils.byteCountToDisplaySize(1023), "1023 bytes");
         assertEquals(FileUtils.byteCountToDisplaySize(1024), "1 KB");
+        assertEquals(FileUtils.byteCountToDisplaySize(1025), "1 KB");
+        assertEquals(FileUtils.byteCountToDisplaySize(1024 * 1023), "1023 KB");
         assertEquals(FileUtils.byteCountToDisplaySize(1024 * 1024), "1 MB");
-        assertEquals(
-            FileUtils.byteCountToDisplaySize(1024 * 1024 * 1024),
-            "1 GB");
+        assertEquals(FileUtils.byteCountToDisplaySize(1024 * 1025), "1 MB");
+        assertEquals(FileUtils.byteCountToDisplaySize(1024 * 1024 * 1023), "1023 MB");
+        assertEquals(FileUtils.byteCountToDisplaySize(1024 * 1024 * 1024), "1 GB");
+        assertEquals(FileUtils.byteCountToDisplaySize(1024 * 1024 * 1025), "1 GB");
+        assertEquals(FileUtils.byteCountToDisplaySize((1024 * 1024 * 1024 * 2) - 1), "1 GB");
+//        assertEquals(FileUtils.byteCountToDisplaySize(1024L * 1024 * 1024 * 1024), "1 TB");
+//        assertEquals(FileUtils.byteCountToDisplaySize(1024L * 1024 * 1024 * 1024 * 1024),
"1 PB");
+//        assertEquals(FileUtils.byteCountToDisplaySize(1024L * 1024 * 1024 * 1024 * 1024
* 1024), "1 EB");
+//        assertEquals(FileUtils.byteCountToDisplaySize(Long.MAX_VALUE), "7 EB");
+        // Other MAX_VALUEs
+        assertEquals(FileUtils.byteCountToDisplaySize(Character.MAX_VALUE), "63 KB");
+        assertEquals(FileUtils.byteCountToDisplaySize(Short.MAX_VALUE), "31 KB");
+        assertEquals(FileUtils.byteCountToDisplaySize(Integer.MAX_VALUE), "1 GB");
     }
 
     //-----------------------------------------------------------------------



Mime
View raw message