hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From William Speirs <wspe...@apache.org>
Subject Re: Guidance on the use of EntityUtils.consume
Date Tue, 06 Dec 2011 22:11:04 GMT
That was the reason I posted the code... it is the same thing.

Bill-
On Dec 6, 2011 4:54 PM, "Todd W Lainhart" <lainhart@us.ibm.com> wrote:

> Understood re the deprecation, but note the javadoc that I quoted which
> describes two different approaches when reacting to the deprecation.  That
> was the heart of my question.
>
>
>
>
> Todd Lainhart
> Rational software
> IBM Corporation
> 550 King Street, Littleton, MA 01460-1250
> 1-978-899-4705
> 2-276-4705 (T/L)
> lainhart@us.ibm.com
>
>
>
>
> From:   William Speirs <wspeirs@apache.org>
> To:     HttpClient User Discussion <httpclient-users@hc.apache.org>
> Date:   12/06/2011 04:46 PM
> Subject:        Re: Guidance on the use of EntityUtils.consume
>
>
>
> 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 <lainhart@us.ibm.com>
> 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: httpclient-users-unsubscribe@hc.apache.org
> > For additional commands, e-mail: httpclient-users-help@hc.apache.org
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message