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/28 16:42:50 UTC
svn commit: r1366694 - in
/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http:
HttpResponse.java util/EntityUtils.java
Author: olegk
Date: Sat Jul 28 14:42:49 2012
New Revision: 1366694
URL: http://svn.apache.org/viewvc?rev=1366694&view=rev
Log:
HTTPCORE-302: Added EntityUtils#updateEntity method (follow-up)
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=1366694&r1=1366693&r2=1366694&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 Sat Jul 28 14:42:49 2012
@@ -131,14 +131,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>),
+ * 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()
+ * @see org.apache.http.util.EntityUtils#updateEntity(HttpResponse, HttpEntity)
*/
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=1366694&r1=1366693&r2=1366694&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 Sat Jul 28 14:42:49 2012
@@ -55,7 +55,7 @@ public final class EntityUtils {
* Ensures that the entity content is fully consumed and the content stream, if exists,
* is closed. The process is done, <i>quietly</i> , without throwing any IOException.
*
- * @param entity
+ * @param entity the entity to consume.
*
*
* @since 4.2
@@ -71,7 +71,7 @@ public final class EntityUtils {
* Ensures that the entity content is fully consumed and the content stream, if exists,
* is closed.
*
- * @param entity
+ * @param entity the entity to consume.
* @throws IOException if an error occurs reading the input stream
*
* @since 4.1
@@ -89,25 +89,29 @@ public final class EntityUtils {
}
/**
- * Updates entity in a response by first consuming an existing entity, then setting the new one.
+ * Updates an 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 response the response with an entity to update; must not be null.
* @param entity the entity to set in the response.
- * @throws IOException if an error occurs while reading the input stream on the existing
+ * @throws IOException if an error occurs while reading the input stream on the existing
* entity.
- *
+ * @throws IllegalArgumentException if response is null.
+ *
* @since 4.3
*/
public static void updateEntity(
final HttpResponse response, final HttpEntity entity) throws IOException {
+ if(response == null) {
+ throw new IllegalArgumentException("Response cannot be null");
+ }
consume(response.getEntity());
response.setEntity(entity);
}
-
+
/**
* Read the contents of an entity and return it as a byte array.
*
- * @param entity
+ * @param entity the entity to read from=
* @return byte array containing the entity content. May be null if
* {@link HttpEntity#getContent()} is null.
* @throws IOException if an error occurs reading the input stream
@@ -270,7 +274,7 @@ public final class EntityUtils {
* The content is converted using the character set from the entity (if any),
* failing that, "ISO-8859-1" is used.
*
- * @param entity
+ * @param entity the entity to convert to a string; must not be null
* @return String containing the content.
* @throws ParseException if header elements cannot be parsed
* @throws IllegalArgumentException if entity is null or if content length > Integer.MAX_VALUE