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 2012/07/26 11:13:22 UTC
svn commit: r1365919 - in
/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http:
HttpResponse.java util/EntityUtils.java
Author: olegk
Date: Thu Jul 26 09:13:21 2012
New Revision: 1365919
URL: http://svn.apache.org/viewvc?rev=1365919&view=rev
Log:
HTTPCORE-302: Added EntityUtils#updateEntity method
Contributed by William R. Speirs <bill.speirs at gmail.com>
Modified:
httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/HttpResponse.java
httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/util/EntityUtils.java
Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/HttpResponse.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/HttpResponse.java?rev=1365919&r1=1365918&r2=1365919&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/HttpResponse.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/HttpResponse.java Thu Jul 26 09:13:21 2012
@@ -130,9 +130,15 @@ public interface HttpResponse extends Ht
/**
* Associates a response entity with this response.
+ * <p/>
+ * Please note that if an entity has already been set for this response and it depends on
+ * an input stream ({@link HttpEntity#isStreaming()} returns <code>true</code>),
+ * it must be fully consumed in order to ensure release of resources.
*
* @param entity the entity to associate with this response, or
* <code>null</code> to unset
+ *
+ * @see HttpEntity#isStreaming()
*/
void setEntity(HttpEntity entity);
Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/util/EntityUtils.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/util/EntityUtils.java?rev=1365919&r1=1365918&r2=1365919&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/util/EntityUtils.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/util/EntityUtils.java Thu Jul 26 09:13:21 2012
@@ -35,6 +35,7 @@ import java.nio.charset.Charset;
import org.apache.http.HeaderElement;
import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.ParseException;
import org.apache.http.entity.ContentType;
@@ -88,6 +89,22 @@ public final class EntityUtils {
}
/**
+ * Updates entity in a response by first consuming an existing entity, then setting the new one.
+ *
+ * @param response the response with an entity to update.
+ * @param entity the entity to set in the response.
+ * @throws IOException if an error occurs while reading the input stream on the existing
+ * entity.
+ *
+ * @since 4.3
+ */
+ public static void updateEntity(
+ final HttpResponse response, final HttpEntity entity) throws IOException {
+ consume(response.getEntity());
+ response.setEntity(entity);
+ }
+
+ /**
* Read the contents of an entity and return it as a byte array.
*
* @param entity