As per the documentation, HttpEntity.consumeContent() is deprecated.
You should use EntityUtils.consume() instead. The code for that is
straightforward:
public static void consume(final HttpEntity entity) throws IOException {
if (entity == null) {
return;
}
if (entity.isStreaming()) {
InputStream instream = entity.getContent();
if (instream != null) {
instream.close();
}
}
}
Bill-
On Tue, Dec 6, 2011 at 2:29 PM, Todd W Lainhart <[email protected]> wrote:
> The javadoc for HttpEntity.consumeContent() is copied below. I can't tell
> if best practice is to use EntityUtils.consume, or just close the input
> stream associated to the entity. I'm guessing the latter, but there may
> be an idiom that I'm missing.
>
> /**
> * This method is deprecated since version 4.1. Please use standard
> * java convention to ensure resource deallocation by calling
> * {@link InputStream#close()} on the input stream returned by
> * {@link #getContent()}
> * <p>
> * This method is called to indicate that the content of this entity
> * is no longer required. All entity implementations are expected to
> * release all allocated resources as a result of this method
> * invocation. Content streaming entities are also expected to
> * dispose of the remaining content, if any. Wrapping entities should
> * delegate this call to the wrapped entity.
> * <p>
> * This method is of particular importance for entities being
> * received from a {@link HttpConnection connection}. The entity
> * needs to be consumed completely in order to re-use the connection
> * with keep-alive.
> *
> * @throws IOException if an I/O error occurs.
> *
> * @deprecated Use {@link
> org.apache.http.util.EntityUtils#consume(HttpEntity)}
> *
> * @see #getContent() and #writeTo(OutputStream)
> */
>
>
>
> -- Todd
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]