--- GetMethod.java.~1.55.~ 2004-11-09 10:00:28.000000000 -0500 +++ GetMethod.java 2004-12-03 22:13:09.000000000 -0500 @@ -70,8 +70,11 @@ // -------------------------------------------------------------- Constants - protected final int BUFFER_SIZE = 2048; + /** The default buffer size */ + protected final int DEFAULT_BUFFER_SIZE = 2048; + /** The maximum buffer size */ + protected final int MAX_BUFFER_SIZE = 200 * 1024; /** @@ -393,7 +396,7 @@ (resourceInputStream, input); // Copy the input stream to the output stream - exception = copyRange(istream, ostream); + exception = copyRange(istream, ostream, resourceInfo.length); // Clean up the input and output streams try { @@ -544,11 +547,12 @@ * @return Exception which occured during processing */ private IOException copyRange(InputStream istream, - ServletOutputStream ostream) { + ServletOutputStream ostream, + long resourceLength) { // Copy the input stream to the output stream IOException exception = null; - byte buffer[] = new byte[input]; + byte buffer[] = new byte[getBufferSize(resourceLength)]; int len = buffer.length; while (true) { try { @@ -591,7 +595,7 @@ IOException exception = null; long bytesToRead = end - start + 1; - byte buffer[] = new byte[input]; + byte buffer[] = new byte[getBufferSize(bytesToRead)]; int len = buffer.length; while ( (bytesToRead > 0) && (len >= buffer.length)) { try { @@ -615,6 +619,16 @@ } + /** + * Get a reasonable buffer size. + */ + private int getBufferSize(long resourceLength) + { + if (resourceLength <= 0) + return DEFAULT_BUFFER_SIZE; + + return (int)Math.min(resourceLength, MAX_BUFFER_SIZE); + } /** * Parse the range header.