You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2015/10/21 10:51:37 UTC

svn commit: r1709770 - /httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/BufferedHttpEntity.java

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;
         }