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 <jnaeg...@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-unsubscr...@hc.apache.org
> For additional commands, e-mail: httpclient-users-h...@hc.apache.org
>
>


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

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

Reply via email to