hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1709770 - /httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/BufferedHttpEntity.java
Date Wed, 21 Oct 2015 08:51:37 GMT
Author: olegk
Date: Wed Oct 21 08:51:37 2015
New Revision: 1709770

URL: http://svn.apache.org/viewvc?rev=1709770&view=rev
Log:
BufferedHttpEntity to use HttpEntity#writeTo when buffering non-repeatable entities

Modified:
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/BufferedHttpEntity.java

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/BufferedHttpEntity.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/BufferedHttpEntity.java?rev=1709770&r1=1709769&r2=1709770&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/BufferedHttpEntity.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/BufferedHttpEntity.java
Wed Oct 21 08:51:37 2015
@@ -28,6 +28,7 @@
 package org.apache.http.entity;
 
 import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -35,7 +36,6 @@ import java.io.OutputStream;
 import org.apache.http.HttpEntity;
 import org.apache.http.annotation.NotThreadSafe;
 import org.apache.http.util.Args;
-import org.apache.http.util.EntityUtils;
 
 /**
  * A wrapping entity that buffers it content if necessary.
@@ -60,7 +60,10 @@ public class BufferedHttpEntity extends
     public BufferedHttpEntity(final HttpEntity entity) throws IOException {
         super(entity);
         if (!entity.isRepeatable() || entity.getContentLength() < 0) {
-            this.buffer = EntityUtils.toByteArray(entity);
+            final ByteArrayOutputStream out = new ByteArrayOutputStream();
+            entity.writeTo(out);
+            out.flush();
+            this.buffer = out.toByteArray();
         } else {
             this.buffer = null;
         }



Mime
View raw message