hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From James Leigh <james-nos...@leighnet.ca>
Subject HttpEntity#writeTo and #consumeContent
Date Thu, 08 Apr 2010 18:18:00 GMT
Hi all,

After looking through the javadocs and the source code it is not clear
to me when writeTo is called if consumeContent also needs to be called.

The javadoc for HttpEntity#isStreaming says this:
        Tells whether this entity depends on an underlying stream.
        Streamed entities should return true until the content has been
        consumed, false afterwards. Self-contained entities should
        return false. Wrapping entities should delegate this call to the
        wrapped entity. 
        The content of a streamed entity is consumed when the stream
        returned by getContent has been read to EOF, or after
        consumeContent has been called. If a streamed entity can not
        detect whether the stream has been read to EOF, it should return
        true until consumeContent is called.

This would indicate that consumeContent should be called after writeTo,
unless isStreaming returns false. The implementation for
BasicHttpEntity#writeTo does not close the content stream, which is
consistent with the above (it requires the caller to also call

        // non-javadoc, see interface HttpEntity
        public void writeTo(final OutputStream outstream) throws IOException {
            if (outstream == null) {
                throw new IllegalArgumentException("Output stream may not be null");
            InputStream instream = getContent();
            int l;
            byte[] tmp = new byte[2048];
            while ((l = instream.read(tmp)) != -1) {
                outstream.write(tmp, 0, l);

However, looking elsewhere in the source code, consumeContent is never
called after writeTo. Here is a code sample from
ThrottlingHttpClientHandler, but similar code can be found in
        HttpEntity entity = request.getEntity();
        OutputStream outstream = new ContentOutputStream(connState.getOutbuffer());

When should the content InputStream get closed? Is the bug in
BasicHttpEntity#writeTo or ThrottlingHttpClientHandler and

Thanks for your time,

To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org

View raw message