hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dan Quaroni...@invoke.com>
Subject Re: HttpClient bounded download size
Date Mon, 12 Dec 2016 22:54:27 GMT
This code is part of a class I made to do this (In this case I needed to
grab the first 128 or so bytes of SWF files so I could parse the display
dimensions):

        HttpGet get = new HttpGet(buildUrl(url));
        try (CloseableHttpResponse response = client.execute(get)) {
            SwfInfo info =
SwfInfo.generateInfo(response.getEntity().getContent());
         }

where generateInfo() takes the input stream from getEntity().getContent()
and then closes it:

private static byte[] getBytes(InputStream fis) {
    try{
< read bytes from the input stream>

        } finally {
            if (fis != null) {
                try {
                    fis.close();
                } catch (IOException ee) {
                }
            }
        }



On Mon, Dec 12, 2016 at 5:47 PM, Joseph Naegele <jnaegele@grierforensics.com
> wrote:

> Hi all, back again.
>
> Now I'm wondering how to properly limit the number of bytes downloaded by
> the synchronous HttpClient (v4.5, i.e. most recent versions).
>
> Like the HttpAsyncClient, even if I only read the desired number of bytes
> from a response entity's InputStream, closing the entity results in the
> remainder of the response entity being downloaded from the connection. I
> found this in ContentLengthInputStream's close method, which is wrapped by
> EofSensorInputStream.
>
> Again, my goal is to intentionally collect a truncated response if it's
> larger than my limit.
>
> Thanks!
> Joe Naegele
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
>


-- 
_________________
*Daniel Quaroni*
*Principal Software Architect*

*office *781.810.2743
*mobile* 617.838.3147
q@invoke.com

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message