cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1034134 - in /cxf/branches/2.2.x-fixes: ./ common/common/src/main/java/org/apache/cxf/helpers/IOUtils.java
Date Thu, 11 Nov 2010 21:17:07 GMT
Author: dkulp
Date: Thu Nov 11 21:17:05 2010
New Revision: 1034134

URL: http://svn.apache.org/viewvc?rev=1034134&view=rev
Log:
Merged revisions 1034117 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/branches/2.3.x-fixes

................
  r1034117 | dkulp | 2010-11-11 15:58:46 -0500 (Thu, 11 Nov 2010) | 13 lines
  
  Merged revisions 1034113 via svnmerge from 
  https://svn.apache.org/repos/asf/cxf/trunk
  
  ........
    r1034113 | dkulp | 2010-11-11 15:50:50 -0500 (Thu, 11 Nov 2010) | 1 line
    
    Add some more method to IOUtils to make it more useful 
  ........
................

Modified:
    cxf/branches/2.2.x-fixes/   (props changed)
    cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/IOUtils.java

Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/IOUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/IOUtils.java?rev=1034134&r1=1034133&r2=1034134&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/IOUtils.java
(original)
+++ cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/IOUtils.java
Thu Nov 11 21:17:05 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) {



Mime
View raw message