Author: ggregory
Date: Tue Jun 12 19:29:22 2012
New Revision: 1349488

URL: http://svn.apache.org/viewvc?rev=1349488&view=rev
Log:
[IO-326] Add new FileUtils.sizeOf[Directory] APIs to return BigInteger. Thanks 
to Bruno P. Kinoshita for the fix and test case.

Modified:
    commons/proper/io/trunk/pom.xml
    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/pom.xml
URL: 
http://svn.apache.org/viewvc/commons/proper/io/trunk/pom.xml?rev=1349488&r1=1349487&r2=1349488&view=diff
==============================================================================
--- commons/proper/io/trunk/pom.xml (original)
+++ commons/proper/io/trunk/pom.xml Tue Jun 12 19:29:22 2012
@@ -24,7 +24,7 @@
   <modelVersion>4.0.0</modelVersion>
   <groupId>commons-io</groupId>
   <artifactId>commons-io</artifactId>
-  <version>2.4-SNAPSHOT</version>
+  <version>2.4</version>
   <name>Commons IO</name>
 
   <inceptionYear>2002</inceptionYear>

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=1349488&r1=1349487&r2=1349488&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 
Tue Jun 12 19:29:22 2012
@@ -2511,7 +2511,7 @@ public class FileUtils {
         for (final File file : files) {
             try {
                 if (!isSymlink(file)) {
-                    size.add(BigInteger.valueOf(sizeOf(file)));
+                    size = size.add(BigInteger.valueOf(sizeOf(file)));
                 }
             } catch (IOException ioe) {
                 // Ignore exceptions caught when asking if a File is a symlink.

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=1349488&r1=1349487&r2=1349488&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
 Tue Jun 12 19:29:22 2012
@@ -64,6 +64,11 @@ public class FileUtilsTestCase extends F
     private static final BigInteger TEST_DIRECTORY_SIZE_BI = BigInteger.ZERO;
     
     /**
+     * Size (greater of zero) of test file.
+     */
+    private static final BigInteger TEST_DIRECTORY_SIZE_GT_ZERO_BI = 
BigInteger.valueOf(100);
+    
+    /**
      * List files recursively
      */
     private static final ListDirectoryWalker LIST_WALKER = new 
ListDirectoryWalker();
@@ -796,7 +801,8 @@ public class FileUtilsTestCase extends F
         try {
             FileUtils.sizeOfDirectoryAsBigInteger(file);
             fail("Exception expected.");
-        } catch (IllegalArgumentException ex) {}
+        } catch (IllegalArgumentException ex) {
+        }
 
         // Creates file
         file.createNewFile();
@@ -806,7 +812,8 @@ public class FileUtilsTestCase extends F
         try {
             FileUtils.sizeOfDirectoryAsBigInteger(file);
             fail("Exception expected.");
-        } catch (IllegalArgumentException ex) {}
+        } catch (IllegalArgumentException ex) {
+        }
 
         // Existing directory
         file.delete();
@@ -814,10 +821,21 @@ public class FileUtilsTestCase extends F
 
         this.createCircularSymLink(file);
 
-        assertEquals(
-            "Unexpected directory size",
-            TEST_DIRECTORY_SIZE_BI,
-            FileUtils.sizeOfDirectoryAsBigInteger(file));
+        assertEquals("Unexpected directory size", TEST_DIRECTORY_SIZE_BI, 
FileUtils.sizeOfDirectoryAsBigInteger(file));
+
+        // Existing directory which size is greater than zero
+        file.delete();
+        file.mkdir();
+
+        File nonEmptyFile = new File(file, "nonEmptyFile" + System.nanoTime());
+        this.createFile(nonEmptyFile, 
TEST_DIRECTORY_SIZE_GT_ZERO_BI.longValue());
+        nonEmptyFile.deleteOnExit();
+
+        assertEquals("Unexpected directory size", 
TEST_DIRECTORY_SIZE_GT_ZERO_BI,
+                FileUtils.sizeOfDirectoryAsBigInteger(file));
+
+        nonEmptyFile.delete();
+        file.delete();
     }
 
     /**


Reply via email to