hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r292015 - /jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/EntityConsumer.java
Date Tue, 27 Sep 2005 18:41:35 GMT
Author: olegk
Date: Tue Sep 27 11:41:30 2005
New Revision: 292015

URL: http://svn.apache.org/viewcvs?rev=292015&view=rev
Log:
Use non-synchronized version of byte array buffer

Modified:
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/EntityConsumer.java

Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/EntityConsumer.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/EntityConsumer.java?rev=292015&r1=292014&r2=292015&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/EntityConsumer.java
(original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/EntityConsumer.java
Tue Sep 27 11:41:30 2005
@@ -29,7 +29,6 @@
 
 package org.apache.http.entity;
 
-import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
@@ -42,6 +41,7 @@
 import org.apache.http.HttpResponse;
 import org.apache.http.NameValuePair;
 import org.apache.http.params.HttpProtocolParams;
+import org.apache.http.util.ByteArrayBuffer;
 
 /**
  * <p>
@@ -87,16 +87,16 @@
             throw new IllegalStateException("HTTP entity too large to be buffered in memory");
         }
         int i = (int)entity.getContentLength();
-        if (i == -1) {
-            i = 0;
+        if (i < 0) {
+            i = 4096;
         }
-        ByteArrayOutputStream outstream = new ByteArrayOutputStream(i);
-        byte[] tmp = new byte[2048];
+        ByteArrayBuffer buffer = new ByteArrayBuffer(i);
+        byte[] tmp = new byte[4096];
         int l;
         while((l = instream.read(tmp)) != -1) {
-            outstream.write(tmp, 0, l);
+        	buffer.append(tmp, 0, l);
         }
-        return outstream.toByteArray();
+        return buffer.getBytes();
     }
         
     public static String getContentCharSet(final HttpEntity entity) {



Mime
View raw message