hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Steve Johnson <sjohn...@mercury.com>
Subject HTTPClient 2.0 - Limiting response body read length
Date Mon, 06 Dec 2004 16:24:17 GMT
Hi All,

 

HTTPClient 2.0 - Limiting response body read length

 

This code seems to indicate that it is not possible to limit how

much stuff gets read. Is this true?

 

 HttpMethodBase.  

 public byte[] getResponseBody() {

        if (this.responseBody == null) {

            try {

                InputStream instream = getResponseBodyAsStream();

                if (instream != null) {

                    LOG.debug("Buffering response body");

                    ByteArrayOutputStream outstream = new ByteArrayOutputStream();

                    byte[] buffer = new byte[4096];

                    int len;

                    while ((len = instream.read(buffer)) > 0) {

                        outstream.write(buffer, 0, len);

                    }

                    outstream.close();

                    setResponseStream(null);

                    this.responseBody = outstream.toByteArray();

                }

            } catch (IOException e) {

                LOG.error("I/O failure reading response body", e);

                this.responseBody = null;

            }

        }

        return this.responseBody;

    }

 

If so, would it be best to override this method with a method

to allow limiting the length like this:

 

while ((len = instream.read(buffer)) > 0 && totalLength+len < MaxDesiredLength)
{

                        totalLength += len;

                        outstream.write(buffer, 0, len);

                    }

 

Thanks for your time and effort,

 

Steve Johnson, Software Engineer, sjohnson@mercury.com

direct 720.564.6532 

www.mercury.com <http://www.mercury.com/>  

 <http://www.mercury.com/> 

 <http://www.mercury.com/>  

 

 


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