You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by "Mike J. M." <mi...@gmail.com> on 2008/02/22 18:27:37 UTC

HttpContentTooLargeException??

I just spotted this in the docs, and I was wondering how to use this class.
Is it even being used by any current classes? I want to limit the size of a
download either before or during downloading. My code right now simply
downloads the whole file and THEN check the size. But that wouldn't work
right because if someone tries to download a file that's 100 MB then it'll
download the whole 100 MB, or timeout, whichever comes first, and then check
the size.
What's the smart way to limit file download sizes, or maybe in this case
response body sizes in HttpClient?

Thanks

Re: HttpContentTooLargeException??

Posted by stephen joseph butler <st...@gmail.com>.
On Fri, Feb 22, 2008 at 11:27 AM, Mike J. M. <mi...@gmail.com> wrote:
> I just spotted this in the docs, and I was wondering how to use this class.
>  Is it even being used by any current classes? I want to limit the size of a
>  download either before or during downloading. My code right now simply
>  downloads the whole file and THEN check the size. But that wouldn't work
>  right because if someone tries to download a file that's 100 MB then it'll
>  download the whole 100 MB, or timeout, whichever comes first, and then check
>  the size.
>  What's the smart way to limit file download sizes, or maybe in this case
>  response body sizes in HttpClient?

I guess you want commons-io ThresholdingOutputStream:

<http://commons.apache.org/io/api-release/org/apache/commons/io/output/ThresholdingOutputStream.html>

Then use IOUtils.copy(InputStream,OutputStream) to read the data from
method.getResponseBodyAsStream().

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