You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2019/11/25 16:33:43 UTC

[commons-io] branch master updated: Use own util APIs.

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 e6c81e6  Use own util APIs.
e6c81e6 is described below

commit e6c81e64a0a485f7d4d133aab8a3e02cc548973b
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Nov 25 11:33:40 2019 -0500

    Use own util APIs.
---
 src/main/java/org/apache/commons/io/IOUtils.java | 22 ++++++++--------------
 1 file changed, 8 insertions(+), 14 deletions(-)

diff --git a/src/main/java/org/apache/commons/io/IOUtils.java b/src/main/java/org/apache/commons/io/IOUtils.java
index e1f9a24..993828a 100644
--- a/src/main/java/org/apache/commons/io/IOUtils.java
+++ b/src/main/java/org/apache/commons/io/IOUtils.java
@@ -706,29 +706,23 @@ public class IOUtils {
      * @throws NullPointerException if either input is null
      * @throws IOException          if an I/O error occurs
      */
-    public static boolean contentEquals(InputStream input1, InputStream input2)
+    @SuppressWarnings("resource")
+    public static boolean contentEquals(final InputStream input1, final InputStream input2)
             throws IOException {
         if (input1 == input2) {
             return true;
         }
-        if (!(input1 instanceof BufferedInputStream)) {
-            input1 = new BufferedInputStream(input1);
-        }
-        if (!(input2 instanceof BufferedInputStream)) {
-            input2 = new BufferedInputStream(input2);
-        }
-
-        int ch = input1.read();
+        final BufferedInputStream bufferedInput1 = buffer(input1);
+        final BufferedInputStream bufferedInput2 = buffer(input2);
+        int ch = bufferedInput1.read();
         while (EOF != ch) {
-            final int ch2 = input2.read();
+            final int ch2 = bufferedInput2.read();
             if (ch != ch2) {
                 return false;
             }
-            ch = input1.read();
+            ch = bufferedInput1.read();
         }
-
-        final int ch2 = input2.read();
-        return ch2 == EOF;
+        return bufferedInput2.read() == EOF;
     }
 
     /**