You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by co...@apache.org on 2015/07/17 17:35:50 UTC

[1/3] cxf git commit: Use IOUtils methods in CachedStreamTestBase to handle stream reading

Repository: cxf
Updated Branches:
  refs/heads/3.0.x-fixes dd618ce58 -> c7b9638cf


Use IOUtils methods in CachedStreamTestBase to handle stream reading

Conflicts:
	core/src/test/java/org/apache/cxf/io/CachedStreamTestBase.java


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/17fef200
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/17fef200
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/17fef200

Branch: refs/heads/3.0.x-fixes
Commit: 17fef20055ca5ae3495e6fe923a9048dab0ac3a7
Parents: dd618ce
Author: Colm O hEigeartaigh <co...@apache.org>
Authored: Fri Jul 17 16:25:07 2015 +0100
Committer: Colm O hEigeartaigh <co...@apache.org>
Committed: Fri Jul 17 16:26:55 2015 +0100

----------------------------------------------------------------------
 .../java/org/apache/cxf/helpers/IOUtils.java    | 23 ++++++-
 .../org/apache/cxf/io/CachedStreamTestBase.java | 67 ++++++++------------
 2 files changed, 46 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/17fef200/core/src/main/java/org/apache/cxf/helpers/IOUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/cxf/helpers/IOUtils.java b/core/src/main/java/org/apache/cxf/helpers/IOUtils.java
index aab3ab9..5fab355 100644
--- a/core/src/main/java/org/apache/cxf/helpers/IOUtils.java
+++ b/core/src/main/java/org/apache/cxf/helpers/IOUtils.java
@@ -229,13 +229,32 @@ public final class IOUtils {
             n = input.read(buffer, 0, n);
         }
     }
+    
+    public static void copyAtLeast(final Reader input, 
+                                   final Writer output,
+                                   int atLeast) throws IOException {
+        final char[] buffer = new char[4096];
+        int n = atLeast > buffer.length ? buffer.length : atLeast;
+        n = input.read(buffer, 0, n);
+        while (-1 != n) {
+            if (n == 0) {
+                throw new IOException("0 bytes read in violation of Reader.read(char[])");
+            }
+            output.write(buffer, 0, n);
+            atLeast -= n;
+            if (atLeast <= 0) {
+                return;
+            }
+            n = atLeast > buffer.length ? buffer.length : atLeast;
+            n = input.read(buffer, 0, n);
+        }
+    }
 
 
     public static void copy(final Reader input, final Writer output,
             final int bufferSize) throws IOException {
         final char[] buffer = new char[bufferSize];
-        int n = 0;
-        n = input.read(buffer);
+        int n = input.read(buffer);
         while (-1 != n) {
             output.write(buffer, 0, n);
             n = input.read(buffer);

http://git-wip-us.apache.org/repos/asf/cxf/blob/17fef200/core/src/test/java/org/apache/cxf/io/CachedStreamTestBase.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/cxf/io/CachedStreamTestBase.java b/core/src/test/java/org/apache/cxf/io/CachedStreamTestBase.java
index 56e35c1..222705c 100755
--- a/core/src/test/java/org/apache/cxf/io/CachedStreamTestBase.java
+++ b/core/src/test/java/org/apache/cxf/io/CachedStreamTestBase.java
@@ -19,17 +19,19 @@
 package org.apache.cxf.io;
 
 import java.io.ByteArrayOutputStream;
+import java.io.Closeable;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.Reader;
+import java.io.StringWriter;
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusFactory;
+import org.apache.cxf.helpers.IOUtils;
 import org.easymock.EasyMock;
 import org.easymock.IMocksControl;
-
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -171,10 +173,8 @@ public abstract class CachedStreamTestBase extends Assert {
         assertEquals("text is not decoded correctly", text, dectext);
 
         // close the partially read stream
-        if (fin instanceof InputStream) {
-            ((InputStream)fin).close();
-        } else if (fin instanceof Reader) {
-            ((Reader)fin).close();
+        if (fin instanceof Closeable) {
+            ((Closeable)fin).close();
         }
 
         // the file is deleted when cos is closed while all the associated inputs are closed
@@ -245,53 +245,27 @@ public abstract class CachedStreamTestBase extends Assert {
     }
     
     private static void close(Object obj) throws IOException {
-        if (obj instanceof CachedOutputStream) {
-            ((CachedOutputStream)obj).close();
-        } else if (obj instanceof CachedWriter) {
-            ((CachedWriter)obj).close();
-        } else if (obj instanceof InputStream) {
-            ((InputStream)obj).close();
-        } else if (obj instanceof Reader) {
-            ((Reader)obj).close();
+        if (obj instanceof Closeable) {
+            ((Closeable)obj).close();
         }
     }
 
     protected static String readFromStream(InputStream is) throws IOException {
-        ByteArrayOutputStream buf = new ByteArrayOutputStream();
-        try {
-            byte[] b = new byte[100];
-            for (;;) {
-                int n = is.read(b, 0, b.length);
-                if (n < 0) {
-                    break;
-                }
-                buf.write(b, 0, n);
-            }
-        } finally {
-            is.close();
+        try (ByteArrayOutputStream buf = new ByteArrayOutputStream()) {
+            IOUtils.copyAndCloseInput(is, buf);
+            return new String(buf.toByteArray(), "UTF-8");
         }
-        return new String(buf.toByteArray(), "UTF-8");
     }
 
     protected static String readPartiallyFromStream(InputStream is, int len) throws IOException {
-        ByteArrayOutputStream buf = new ByteArrayOutputStream();
-        byte[] b = new byte[len];
-        int rn = 0;
-        for (;;) {
-            int n = is.read(b, 0, b.length);
-            if (n < 0) {
-                break;
-            }
-            buf.write(b, 0, n);
-            rn += n;
-            if (len <= rn) {
-                break;
-            }
+        try (ByteArrayOutputStream buf = new ByteArrayOutputStream()) {
+            IOUtils.copyAtLeast(is, buf, len);
+            return new String(buf.toByteArray(), "UTF-8");
         }
-        return new String(buf.toByteArray(), "UTF-8");
     }
  
     protected static String readFromReader(Reader is) throws IOException {
+<<<<<<< HEAD
         StringBuffer buf = new StringBuffer();
         try {
             char[] b = new char[100];
@@ -304,11 +278,16 @@ public abstract class CachedStreamTestBase extends Assert {
             }
         } finally {
             is.close();
+=======
+        try (StringWriter writer = new StringWriter()) {
+            IOUtils.copyAndCloseInput(is, writer);
+            return writer.toString();
+>>>>>>> 17f140e... Use IOUtils methods in CachedStreamTestBase to handle stream reading
         }
-        return buf.toString();
     }
     
     protected static String readPartiallyFromReader(Reader is, int len) throws IOException {
+<<<<<<< HEAD
         StringBuffer buf = new StringBuffer();
         char[] b = new char[len];
         int rn = 0;
@@ -322,8 +301,12 @@ public abstract class CachedStreamTestBase extends Assert {
             if (len <= rn) {
                 break;
             }
+=======
+        try (StringWriter writer = new StringWriter()) {
+            IOUtils.copyAtLeast(is, writer, len);
+            return writer.toString();
+>>>>>>> 17f140e... Use IOUtils methods in CachedStreamTestBase to handle stream reading
         }
-        return buf.toString();
     }
     
     private static String initTestData(int packetSize) {


[2/3] cxf git commit: Recording .gitmergeinfo Changes

Posted by co...@apache.org.
Recording .gitmergeinfo Changes


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/17f221b2
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/17f221b2
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/17f221b2

Branch: refs/heads/3.0.x-fixes
Commit: 17f221b25e01a9c5824b0005b30e8aee0668fea7
Parents: 17fef20
Author: Colm O hEigeartaigh <co...@apache.org>
Authored: Fri Jul 17 16:26:56 2015 +0100
Committer: Colm O hEigeartaigh <co...@apache.org>
Committed: Fri Jul 17 16:26:56 2015 +0100

----------------------------------------------------------------------
 .gitmergeinfo | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/17f221b2/.gitmergeinfo
----------------------------------------------------------------------
diff --git a/.gitmergeinfo b/.gitmergeinfo
index 64221a9..895c8dc 100644
--- a/.gitmergeinfo
+++ b/.gitmergeinfo
@@ -400,6 +400,7 @@ M 12d070f4392316cdfff03eb41abe22531ed64ee9
 M 16ffa0f10dac874cd5727d312ac56a78b13e5ca9
 M 1701e6c8d4e794f25d69781e3f69357723ad7fcf
 M 174bd11dcfeae47998723757542abe56c792cc76
+M 17f140eb2bf93444e7f8e028b45a371d14688cda
 M 18a3d43cb0044fcb84d3cc89f138fd9e7110dd04
 M 1946e323a0df6e5f9748af82106cff39d7b5d01f
 M 19e912e8d4b6d3f3a4c2b88b1d53e691496d7dc0


[3/3] cxf git commit: Fixing backmerge

Posted by co...@apache.org.
Fixing backmerge


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/c7b9638c
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/c7b9638c
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/c7b9638c

Branch: refs/heads/3.0.x-fixes
Commit: c7b9638cf60cc38342828192f5ce80e4a81ce9a3
Parents: 17f221b
Author: Colm O hEigeartaigh <co...@apache.org>
Authored: Fri Jul 17 16:35:40 2015 +0100
Committer: Colm O hEigeartaigh <co...@apache.org>
Committed: Fri Jul 17 16:35:40 2015 +0100

----------------------------------------------------------------------
 .../org/apache/cxf/io/CachedStreamTestBase.java | 49 ++++++--------------
 1 file changed, 15 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/c7b9638c/core/src/test/java/org/apache/cxf/io/CachedStreamTestBase.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/cxf/io/CachedStreamTestBase.java b/core/src/test/java/org/apache/cxf/io/CachedStreamTestBase.java
index 222705c..211e928 100755
--- a/core/src/test/java/org/apache/cxf/io/CachedStreamTestBase.java
+++ b/core/src/test/java/org/apache/cxf/io/CachedStreamTestBase.java
@@ -251,61 +251,42 @@ public abstract class CachedStreamTestBase extends Assert {
     }
 
     protected static String readFromStream(InputStream is) throws IOException {
-        try (ByteArrayOutputStream buf = new ByteArrayOutputStream()) {
+        ByteArrayOutputStream buf = new ByteArrayOutputStream();
+        try {
             IOUtils.copyAndCloseInput(is, buf);
             return new String(buf.toByteArray(), "UTF-8");
+        } finally {
+            buf.close();
         }
     }
 
     protected static String readPartiallyFromStream(InputStream is, int len) throws IOException {
-        try (ByteArrayOutputStream buf = new ByteArrayOutputStream()) {
+        ByteArrayOutputStream buf = new ByteArrayOutputStream();
+        try {
             IOUtils.copyAtLeast(is, buf, len);
             return new String(buf.toByteArray(), "UTF-8");
+        } finally {
+            buf.close();
         }
     }
  
     protected static String readFromReader(Reader is) throws IOException {
-<<<<<<< HEAD
-        StringBuffer buf = new StringBuffer();
+        StringWriter writer = new StringWriter();
         try {
-            char[] b = new char[100];
-            for (;;) {
-                int n = is.read(b, 0, b.length);
-                if (n < 0) {
-                    break;
-                }
-                buf.append(b, 0, n);
-            }
-        } finally {
-            is.close();
-=======
-        try (StringWriter writer = new StringWriter()) {
             IOUtils.copyAndCloseInput(is, writer);
             return writer.toString();
->>>>>>> 17f140e... Use IOUtils methods in CachedStreamTestBase to handle stream reading
+        } finally {
+            writer.close();
         }
     }
     
     protected static String readPartiallyFromReader(Reader is, int len) throws IOException {
-<<<<<<< HEAD
-        StringBuffer buf = new StringBuffer();
-        char[] b = new char[len];
-        int rn = 0;
-        for (;;) {
-            int n = is.read(b, 0, b.length);
-            if (n < 0) {
-                break;
-            }
-            buf.append(b, 0, n);
-            rn += n;
-            if (len <= rn) {
-                break;
-            }
-=======
-        try (StringWriter writer = new StringWriter()) {
+        StringWriter writer = new StringWriter();
+        try {
             IOUtils.copyAtLeast(is, writer, len);
             return writer.toString();
->>>>>>> 17f140e... Use IOUtils methods in CachedStreamTestBase to handle stream reading
+        } finally {
+            writer.close();
         }
     }