You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2010/11/11 21:50:50 UTC

svn commit: r1034113 - in /cxf/trunk: common/common/src/main/java/org/apache/cxf/helpers/IOUtils.java systests/databinding/src/test/java/org/apache/cxf/systest/aegis/mtom/MtomTest.java

Author: dkulp
Date: Thu Nov 11 20:50:50 2010
New Revision: 1034113

URL: http://svn.apache.org/viewvc?rev=1034113&view=rev
Log:
Add some more method to IOUtils to make it more useful and replace the commons version in the tests

Modified:
    cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/IOUtils.java
    cxf/trunk/systests/databinding/src/test/java/org/apache/cxf/systest/aegis/mtom/MtomTest.java

Modified: cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/IOUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/IOUtils.java?rev=1034113&r1=1034112&r2=1034113&view=diff
==============================================================================
--- cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/IOUtils.java (original)
+++ cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/IOUtils.java Thu Nov 11 20:50:50 2010
@@ -23,6 +23,7 @@ import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.InputStreamReader;
 import java.io.OutputStream;
 import java.io.Reader;
 import java.io.UnsupportedEncodingException;
@@ -161,34 +162,33 @@ public final class IOUtils {
     public static String toString(final InputStream input) throws IOException {
         return toString(input, DEFAULT_BUFFER_SIZE);
     }
-
+    public static String toString(final InputStream input, String charset) throws IOException {
+        return toString(input, DEFAULT_BUFFER_SIZE, charset);
+    }
     public static String toString(final InputStream input, int bufferSize)
         throws IOException {
+        return toString(input, bufferSize, null);
+    }
+    public static String toString(final InputStream input, int bufferSize, String charset)
+        throws IOException {
 
+        
         int avail = input.available();
         if (avail > bufferSize) {
             bufferSize = avail;
         }
-
-        StringBuilder buf = new StringBuilder();
-        final byte[] buffer = new byte[bufferSize];
-        int n = 0;
-        n = input.read(buffer);
-        while (-1 != n) {
-            if (n == 0) {
-                throw new IOException("0 bytes read in violation of InputStream.read(byte[])");
-            }
-            buf.append(newStringFromBytes(buffer, 0, n));
-            n = input.read(buffer);
-        }
-        input.close();
-        return buf.toString();
+        Reader reader = charset == null ? new InputStreamReader(input, UTF8_CHARSET) 
+            : new InputStreamReader(input, charset);
+        return toString(reader, bufferSize);
     }
 
     public static String toString(final Reader input) throws IOException {
+        return toString(input, DEFAULT_BUFFER_SIZE);
+    }
+    public static String toString(final Reader input, int bufSize) throws IOException {
 
         StringBuilder buf = new StringBuilder();
-        final char[] buffer = new char[DEFAULT_BUFFER_SIZE];
+        final char[] buffer = new char[bufSize];
         int n = 0;
         n = input.read(buffer);
         while (-1 != n) {

Modified: cxf/trunk/systests/databinding/src/test/java/org/apache/cxf/systest/aegis/mtom/MtomTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/databinding/src/test/java/org/apache/cxf/systest/aegis/mtom/MtomTest.java?rev=1034113&r1=1034112&r2=1034113&view=diff
==============================================================================
--- cxf/trunk/systests/databinding/src/test/java/org/apache/cxf/systest/aegis/mtom/MtomTest.java (original)
+++ cxf/trunk/systests/databinding/src/test/java/org/apache/cxf/systest/aegis/mtom/MtomTest.java Thu Nov 11 20:50:50 2010
@@ -31,13 +31,13 @@ import org.w3c.dom.Document;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 
-import org.apache.commons.io.IOUtils;
 import org.apache.cxf.Bus;
 import org.apache.cxf.aegis.databinding.AegisDatabinding;
 import org.apache.cxf.aegis.type.mtom.AbstractXOPType;
 import org.apache.cxf.common.util.SOAPConstants;
 import org.apache.cxf.endpoint.Server;
 import org.apache.cxf.frontend.ClientProxyFactoryBean;
+import org.apache.cxf.helpers.IOUtils;
 import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
 import org.apache.cxf.systest.aegis.mtom.fortest.DataHandlerBean;
 import org.apache.cxf.systest.aegis.mtom.fortest.MtomTestImpl;