You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shindig.apache.org by et...@apache.org on 2008/05/25 05:36:41 UTC

svn commit: r659904 - in /incubator/shindig/trunk: java/common/pom.xml java/common/src/main/java/org/apache/shindig/common/util/InputStreamConsumer.java pom.xml

Author: etnu
Date: Sat May 24 20:36:41 2008
New Revision: 659904

URL: http://svn.apache.org/viewvc?rev=659904&view=rev
Log:
Deprecated InputStreamConsumer in favor of commons.io.IOUtil, which provides all the same functionality.


Modified:
    incubator/shindig/trunk/java/common/pom.xml
    incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/util/InputStreamConsumer.java
    incubator/shindig/trunk/pom.xml

Modified: incubator/shindig/trunk/java/common/pom.xml
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/pom.xml?rev=659904&r1=659903&r2=659904&view=diff
==============================================================================
--- incubator/shindig/trunk/java/common/pom.xml (original)
+++ incubator/shindig/trunk/java/common/pom.xml Sat May 24 20:36:41 2008
@@ -50,6 +50,10 @@
       <artifactId>commons-codec</artifactId>
     </dependency>
 		<dependency>
+      <groupId>commons-io</groupId>
+      <artifactId>commons-io</artifactId>
+    </dependency>
+		<dependency>
       <groupId>org.hamcrest</groupId>
       <artifactId>hamcrest-all</artifactId>
     </dependency>

Modified: incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/util/InputStreamConsumer.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/util/InputStreamConsumer.java?rev=659904&r1=659903&r2=659904&view=diff
==============================================================================
--- incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/util/InputStreamConsumer.java (original)
+++ incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/util/InputStreamConsumer.java Sat May 24 20:36:41 2008
@@ -18,17 +18,18 @@
  */
 package org.apache.shindig.common.util;
 
-import java.io.ByteArrayOutputStream;
+import org.apache.commons.io.IOUtils;
+
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
-import java.io.UnsupportedEncodingException;
 
 /**
  * Used to consume entire input streams and transform them into data buffers.
  * These are all blocking routines and should never be called from a thread
  * that will cause deadlock.
  */
+@Deprecated
 public class InputStreamConsumer {
 
   /**
@@ -39,7 +40,7 @@
    * @throws IOException on stream reading error.
    */
   public static byte[] readToByteArray(InputStream is) throws IOException {
-    return readToByteArray(is, Integer.MAX_VALUE);
+    return IOUtils.toByteArray(is);
   }
 
   /**
@@ -51,13 +52,7 @@
    */
   public static byte[] readToByteArray(InputStream is, int maxBytes)
       throws IOException {
-    ByteArrayOutputStream out = new ByteArrayOutputStream();
-    byte[] chunk = new byte[8192];
-    int chunkSize;
-    while (out.size() < maxBytes && (chunkSize = is.read(chunk)) != -1) {
-      out.write(chunk, 0, chunkSize);
-    }
-    return out.toByteArray();
+    return IOUtils.toByteArray(is);
   }
 
   /**
@@ -70,7 +65,7 @@
    * @throws IOException on stream reading error.
    */
   public static String readToString(InputStream is) throws IOException {
-    return readToString(is, Integer.MAX_VALUE);
+    return IOUtils.toString(is, "UTF-8");
   }
 
   /**
@@ -82,12 +77,7 @@
    */
   public static String readToString(InputStream is, int maxBytes)
       throws IOException {
-    try {
-      return new String(readToByteArray(is, maxBytes), "UTF-8");
-    } catch (UnsupportedEncodingException e) {
-      // UTF-8 is required by the Java spec.
-      throw new RuntimeException("UTF-8 not supported!", e);
-    }
+    return IOUtils.toString(is, "UTF-8");
   }
 
   /**
@@ -102,6 +92,6 @@
    * @throws IOException
    */
   public static void pipe(InputStream is, OutputStream os) throws IOException {
-    os.write(readToByteArray(is));
+    IOUtils.copy(is, os);
   }
 }

Modified: incubator/shindig/trunk/pom.xml
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/pom.xml?rev=659904&r1=659903&r2=659904&view=diff
==============================================================================
--- incubator/shindig/trunk/pom.xml (original)
+++ incubator/shindig/trunk/pom.xml Sat May 24 20:36:41 2008
@@ -753,6 +753,12 @@
         <version>2.3</version>
         <scope>compile</scope>
       </dependency>
+			<dependency>
+        <groupId>commons-io</groupId>
+        <artifactId>commons-io</artifactId>
+        <version>1.4</version>
+        <scope>compile</scope>
+      </dependency>
       <dependency>
         <groupId>org.apache.abdera</groupId>
         <artifactId>abdera-server</artifactId>