commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ortwin Glück" <>
Subject Re: [HttpClient] Retriving an unbuffered stream
Date Fri, 23 Aug 2002 08:15:40 GMT
To achieve this we clearly need to change the way HttpMethods handle the 
response stream. Currently it is read entirely, even though this is 
completely unnecessary.

The following needs to be done:

1. Refactor ResponseInputStream. Even a chunked response should not be 
buffered partially. Add more state information to keep track where in 
the chunked stream we are and just return the appropriate data on a read 
without using buffers.
A separate ChunkedInputStream class would be a great help in separating 
functionality. (I have such a class ready and can contribute it if 
needed.) So ResponseInputStream only has to decide if to wrap the 
InputStream from the socket into this ChunkedInputStream or forward the 
  data directly.

2. Change HttpMethodBase.responseBody to be of type InputStream. If we 
need the data as String we can always read it in completely (I don't 
favor this idea and consider this the responsibility of the application 
and not the HttpClient. Deliviring a InputStream is all we need). Same 
applies to buffering in a disk file. This also reduces array copy 
(The all-over strategy of any protocol should be to use as little copy 
operations as possible anyway. This is a common problem with ultra high 
bandwiths and certain IP stacks for example.)

awaiting your comments.


Jeff Dever wrote:
> Hmmmm,
> I don't see any way to get an unbuffered output stream.  There is a public
> ResponseInputStream class in HttpClient that handles chunking and such but I
> don't see any reasonable way of getting at it from a HttpMethod.  Even if
> you could access it, the response would have already been buffered in a
> byte[] after the execute() method is called.
> As Mark noted, the getResponseBodyAsStream() is not particularly useful and
> only saves the caller from doing a stream = new
> ByteArrayInputStream(method.getResponseBody()).
> Anyone have any ideas on this?

  NOSE applied intelligence ag      [perspectix-nose digital b.i]
  ortwin glück                      [email]
  hardturmstrasse 171               [office]      +41-1-277 57 35
  8005 zurich                       [fax]         +41-1-277 57 12

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message