Index: src/java/org/apache/commons/httpclient/HttpMethodBase.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v retrieving revision 1.159.2.30 diff -u -r1.159.2.30 HttpMethodBase.java --- src/java/org/apache/commons/httpclient/HttpMethodBase.java 27 Jul 2004 01:34:48 -0000 1.159.2.30 +++ src/java/org/apache/commons/httpclient/HttpMethodBase.java 4 Aug 2004 01:55:49 -0000 @@ -679,9 +679,15 @@ InputStream instream = getResponseBodyAsStream(); if (instream != null) { LOG.debug("Buffering response body"); - ByteArrayOutputStream outstream = new ByteArrayOutputStream(); - byte[] buffer = new byte[4096]; - int len; + + int contentLength = getResponseContentLength(); + if (contentLength < 0) { + // content length is not known, we'll use a default size + contentLength = 4096; + } + ByteArrayOutputStream outstream = new ByteArrayOutputStream(contentLength); + byte[] buffer = new byte[Math.min(4096, contentLength)]; + int len = 0; while ((len = instream.read(buffer)) > 0) { outstream.write(buffer, 0, len); }