Thanks much for the advice, Oleg; that worked great. For any interested, I'm attaching the source of the class.
Todd On Thu, 26 Aug 2010 10:33 +0200, "Oleg Kalnichevski" <[email protected]> wrote: > On Tue, 2010-08-24 at 16:06 -0600, Todd Wilson wrote: > > Greetings, > > > > I'm transitioning from HttpClient 3 to 4. I believe I've done all of > > the necessary translations except for downloading a partial response. > > For example, there are cases where the server response may be very > > large, but I'm only interested in the first 50K or so. In HttpClient 3 > > I handled this with ContentLengthInputStream, which basically took an > > InputStream and the number of bytes to be read. Nice and easy. In > > HttpClient 4 it's probably equally easy, but I can't figure out just how > > to go about it. The new version of ContentLengthInputStream (found in > > HttpComponents Core) takes a SessionInputBuffer, in addition to the > > number of bytes to be read. The trouble is, I can't figure out how to > > generate a SessionInputBuffer out of an InputStream (or something like > > it) that I might get from the response entity. Any tips on how to go > > about what I'm describing? > > > > You could extend the AbstractSessionInputBuffer and make it work with > any arbitrary input stream, but I think that would be an overkill if all > you want is to limit the number of bytes readable from an input stream. > > You will probably be much better off coping and customizing the old > class from HttpClient 3.x > > http://svn.apache.org/repos/asf/httpcomponents/oac.hc3x/trunk/src/java/org/apache/commons/httpclient/ContentLengthInputStream.java > > You might also consider contributing it to Apache Commons IO. I was > pretty surprised to not have found a similar class in Commons IO > > Hope this helps > > Oleg > > > > --------------------------------------------------------------------- > 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]
