Author: ggregory
Date: Fri Jan  4 15:57:10 2013
New Revision: 1428941

URL: http://svn.apache.org/viewvc?rev=1428941&view=rev
Log:
[IO-362] IOUtils.contentEquals* methods returns false if input1 == input2, 
should return true.

Modified:
    commons/proper/io/trunk/src/changes/changes.xml
    commons/proper/io/trunk/src/main/java/org/apache/commons/io/IOUtils.java
    
commons/proper/io/trunk/src/test/java/org/apache/commons/io/IOUtilsTestCase.java

Modified: commons/proper/io/trunk/src/changes/changes.xml
URL: 
http://svn.apache.org/viewvc/commons/proper/io/trunk/src/changes/changes.xml?rev=1428941&r1=1428940&r2=1428941&view=diff
==============================================================================
--- commons/proper/io/trunk/src/changes/changes.xml (original)
+++ commons/proper/io/trunk/src/changes/changes.xml Fri Jan  4 15:57:10 2013
@@ -46,7 +46,10 @@ The <action> type attribute can be add,u
 
   <body>
     <!-- The release date is the date RC is cut -->
-    <release version="2.5" date="201?-??-??" description="New features and bug 
fixes.">    
+    <release version="2.5" date="2013-??-??" description="New features and bug 
fixes.">    
+      <action issue="IO-362" dev="ggregory" type="fix" due-to="mmadson, 
ggregory">
+        IOUtils.contentEquals* methods returns false if input1 == input2, 
should return true.
+      </action>            
       <action issue="IO-361" dev="ggregory" type="add">
         Add API FileUtils.forceMkdirsParent().
       </action>            

Modified: 
commons/proper/io/trunk/src/main/java/org/apache/commons/io/IOUtils.java
URL: 
http://svn.apache.org/viewvc/commons/proper/io/trunk/src/main/java/org/apache/commons/io/IOUtils.java?rev=1428941&r1=1428940&r2=1428941&view=diff
==============================================================================
--- commons/proper/io/trunk/src/main/java/org/apache/commons/io/IOUtils.java 
(original)
+++ commons/proper/io/trunk/src/main/java/org/apache/commons/io/IOUtils.java 
Fri Jan  4 15:57:10 2013
@@ -2212,6 +2212,9 @@ public class IOUtils {
      */
     public static boolean contentEquals(InputStream input1, InputStream input2)
             throws IOException {
+        if (input1 == input2) {
+            return true;
+        }
         if (!(input1 instanceof BufferedInputStream)) {
             input1 = new BufferedInputStream(input1);
         }
@@ -2249,7 +2252,10 @@ public class IOUtils {
      */
     public static boolean contentEquals(Reader input1, Reader input2)
             throws IOException {
-        
+        if (input1 == input2) {
+            return true;
+        }
+
         input1 = toBufferedReader(input1);
         input2 = toBufferedReader(input2);
 
@@ -2282,6 +2288,9 @@ public class IOUtils {
      */
     public static boolean contentEqualsIgnoreEOL(final Reader input1, final 
Reader input2)
             throws IOException {
+        if (input1 == input2) {
+            return true;
+        }
         final BufferedReader br1 = toBufferedReader(input1);
         final BufferedReader br2 = toBufferedReader(input2);
 

Modified: 
commons/proper/io/trunk/src/test/java/org/apache/commons/io/IOUtilsTestCase.java
URL: 
http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/IOUtilsTestCase.java?rev=1428941&r1=1428940&r2=1428941&view=diff
==============================================================================
--- 
commons/proper/io/trunk/src/test/java/org/apache/commons/io/IOUtilsTestCase.java
 (original)
+++ 
commons/proper/io/trunk/src/test/java/org/apache/commons/io/IOUtilsTestCase.java
 Fri Jan  4 15:57:10 2013
@@ -16,6 +16,7 @@
  */
 package org.apache.commons.io;
 
+import java.io.BufferedInputStream;
 import java.io.BufferedReader;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
@@ -205,7 +206,36 @@ public class IOUtilsTestCase extends Fil
         }
     }
 
+    public void testContentEquals_InputStream_InputStream() throws Exception {
+        {
+            final ByteArrayInputStream input1 = new 
ByteArrayInputStream("".getBytes(Charsets.UTF_8));
+            assertTrue(IOUtils.contentEquals(input1, input1));
+        }
+        {
+            final ByteArrayInputStream input1 = new 
ByteArrayInputStream("ABC".getBytes(Charsets.UTF_8));
+            assertTrue(IOUtils.contentEquals(input1, input1));
+        }
+        assertTrue(IOUtils
+                .contentEquals(new 
ByteArrayInputStream("".getBytes(Charsets.UTF_8)), new 
ByteArrayInputStream("".getBytes(Charsets.UTF_8))));
+        assertTrue(IOUtils.contentEquals(new BufferedInputStream(new 
ByteArrayInputStream("".getBytes(Charsets.UTF_8))), new BufferedInputStream(
+                new ByteArrayInputStream("".getBytes(Charsets.UTF_8)))));
+        assertTrue(IOUtils.contentEquals(new 
ByteArrayInputStream("ABC".getBytes(Charsets.UTF_8)),
+                new ByteArrayInputStream("ABC".getBytes(Charsets.UTF_8))));
+        assertFalse(IOUtils.contentEquals(new 
ByteArrayInputStream("ABCD".getBytes(Charsets.UTF_8)),
+                new ByteArrayInputStream("ABC".getBytes(Charsets.UTF_8))));
+        assertFalse(IOUtils.contentEquals(new 
ByteArrayInputStream("ABC".getBytes(Charsets.UTF_8)),
+                new ByteArrayInputStream("ABCD".getBytes(Charsets.UTF_8))));
+    }
+
     public void testContentEquals_Reader_Reader() throws Exception {
+        {
+            final StringReader input1 = new StringReader("");
+            assertTrue(IOUtils.contentEquals(input1, input1));
+        }
+        {
+            final StringReader input1 = new StringReader("ABC");
+            assertTrue(IOUtils.contentEquals(input1, input1));
+        }
         assertTrue(IOUtils.contentEquals(new StringReader(""), new 
StringReader("")));
         assertTrue(IOUtils.contentEquals(new BufferedReader(new 
StringReader("")), new BufferedReader(new StringReader(""))));
         assertTrue(IOUtils.contentEquals(new StringReader("ABC"), new 
StringReader("ABC")));
@@ -214,6 +244,15 @@ public class IOUtilsTestCase extends Fil
     }
 
     public void testContentEqualsIgnoreEOL() throws Exception {
+        {
+            final Reader input1 = new CharArrayReader("".toCharArray());
+            assertTrue(IOUtils.contentEqualsIgnoreEOL(input1, input1));
+        }
+        {
+            final Reader input1 =  new 
CharArrayReader("321\r\n".toCharArray());
+            assertTrue(IOUtils.contentEqualsIgnoreEOL(input1, input1));
+        }
+
         Reader r1;
         Reader r2;
 


Reply via email to