Nops, depending on the implementation of a certain VM (and the underlying Socket and Buffered streams) and the way the network packages are received, it is possible that an 8k content be delivered as 8 packages of 1k, for instance. BufferedInputStream will use InputStream.available() to determine whether to keep reading or not. Actually, it appears that that particular read(byte[]) signature you're using is not even overridden by BufferInputStream, so I don't think it's adding any behaviour except calling the underlying stream. Check http://www.docjar.com/docs/api/java/io/BufferedInputStream.html
It might be unlikely it will break, and if you're satisfied with the JVM you're running, keep doing it. Be careful when testing under a different system or JVM. Just in case, you can also check removing your buffer and see if it affects your performance. []s Gus -----Original Message----- From: Tony Spencer [mailto:[EMAIL PROTECTED] Sent: July 21, 2005 2:58 PM To: HttpClient User Discussion Subject: Re: How to limit the response size Hi Gustavo, Maybe I misunderstand you but isn't that what the code sample I provided doing? Its using a stream to read until the total desired size is reached (in this case 8k instead of 100k). I then attempt to close the connection with method.releaseConnection(); but it just hangs. Oleg, I tried your suggestion of using method.abort but it also just hangs on the test url http://www.tfc-charts.w2d.com/chart/dw/w On 7/21/05, Oleg Kalnichevski <[EMAIL PROTECTED]> wrote: > Just call HttpMethod#abort to close the underlying connection > > Oleg > > > On Thu, 2005-07-21 at 16:34 -0400, Tony Spencer wrote: > > Ok, I managed to limit the the response to 8k in the following code > > but it doesn't help with what I'm really trying to accomplish. > > Sometimes there is a site that will spew a neverending response. This > > causes HttpClient to hang indefinitely. My code below does not solve > > the problem. Here is an example of a nasty site that never stops > > sending response: http://www.tfc-charts.w2d.com/chart/dw/w (beware. > > it may crash your browser if you browse it) > > > > InputStream is = method.getResponseBodyAsStream(); > > BufferedInputStream bis = new BufferedInputStream(is); > > byte[] bytes = new byte[ 8192 ]; > > bis.read(bytes); > > bis.close(); > > is.close(); > > ret = new String(bytes); > > > > > > On 7/21/05, Tony Spencer <[EMAIL PROTECTED]> wrote: > > > I'd like to limit the size of the response but don't know how. For > > > instance, if the response body is greater than 100k I would like to > > > close the connection to the site. How can I go about doing this? I > > > see the available method param : BUFFER_WARN_TRIGGER_LIMIT but it only > > > seems to control warning logging. > > > > > > Currently I receive the response body like so: > > > byte[] bytes = method.getResponseBody(); > > > > > > Any help greatly appreciated. > > > > > > > --------------------------------------------------------------------- > > 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] > > --------------------------------------------------------------------- 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]
