? HttpClient 2.0.iml ? HttpClient 2.0.ipr ? HttpClient 2.0.iws ? markreset.patch ? sslguide.patch ? lib/junit.jar ? xdocs/sslguide2.patch Index: src/java/org/apache/commons/httpclient/ContentLengthInputStream.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/ContentLengthInputStream.java,v retrieving revision 1.6.2.2 diff -u -r1.6.2.2 ContentLengthInputStream.java --- src/java/org/apache/commons/httpclient/ContentLengthInputStream.java 9 Aug 2004 01:22:05 -0000 1.6.2.2 +++ src/java/org/apache/commons/httpclient/ContentLengthInputStream.java 29 Sep 2004 23:56:34 -0000 @@ -31,20 +31,36 @@ package org.apache.commons.httpclient; -import java.io.FilterInputStream; import java.io.IOException; import java.io.InputStream; /** * Cuts the wrapped InputStream off after a specified number of bytes. * + *
Implementation note: Choices abound. One approach would pass + * through the {@link InputStream#mark} and {@link InputStream#reset} calls to + * the underlying stream. That's tricky, though, because you then have to + * start duplicating the work of keeping track of how much a reset rewinds. + * Further, you have to watch out for the "readLimit", and since the semantics + * for the readLimit leave room for differing implementations, you might get + * into a lot of trouble.
+ * + *Alternatively, you could make this class extend {@link java.io.BufferedInputStream} + * and then use the protected members of that class to avoid duplicated effort. + * That solution has the side effect of adding yet another possible layer of + * buffering.
+ * + *Then, there is the simple choice, which this takes - simply don't + * support {@link InputStream#mark} and {@link InputStream#reset}. That choice + * has the added benefit of keeping this class very simple.
+ * * @author Ortwin Gl?ck * @author Eric Johnson * @author Mike Bowler * @since 2.0 */ -public class ContentLengthInputStream extends FilterInputStream { +public class ContentLengthInputStream extends InputStream { /** * The maximum number of bytes that can be read from the stream. Subsequent @@ -59,6 +75,11 @@ private boolean closed = false; /** + * Wrapped input stream that all calls are delegated to. + */ + private InputStream wrappedStream; + + /** * Creates a new length limited stream * * @param in The stream to wrap @@ -66,7 +87,7 @@ * the stream. Subsequent read operations will return -1. */ public ContentLengthInputStream(InputStream in, int contentLength) { - super(in); + wrappedStream = in; this.contentLength = contentLength; } @@ -105,7 +126,7 @@ return -1; } pos++; - return super.read(); + return wrappedStream.read(); } /** @@ -132,7 +153,7 @@ if (pos + len > contentLength) { len = contentLength - pos; } - int count = super.read(b, off, len); + int count = wrappedStream.read(b, off, len); pos += count; return count; } @@ -162,7 +183,7 @@ // still available long length = Math.min(n, contentLength - pos); // skip and keep track of the bytes actually skipped - length = super.skip(length); + length = wrappedStream.skip(length); // only add the skipped bytes to the current position // if bytes were actually skipped if (length > 0) {