Index: 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 --- java/org/apache/commons/httpclient/ContentLengthInputStream.java 9 Aug 2004 01:22:05 -0000 1.6.2.2 +++ java/org/apache/commons/httpclient/ContentLengthInputStream.java 29 Sep 2004 21:14:04 -0000 @@ -54,6 +54,8 @@ /** The current position */ private int pos = 0; + private int markpos = 0; + private boolean inmark = false; /** True if the stream is closed. */ private boolean closed = false; @@ -105,9 +107,24 @@ return -1; } pos++; + if (inmark) markpos ++; return super.read(); } + public void mark(int readlimit) { + super.mark(readlimit); + inmark = true; + markpos = 0; + } + + public void reset() throws IOException { + inmark = false; + super.reset(); + pos = pos - markpos; + markpos = 0; + } + + /** * Does standard {@link InputStream#read(byte[], int, int)} behavior, but * also notifies the watcher when the contents have been consumed. @@ -133,6 +150,7 @@ len = contentLength - pos; } int count = super.read(b, off, len); + if (inmark) markpos += count; pos += count; return count; } @@ -167,6 +185,7 @@ // if bytes were actually skipped if (length > 0) { pos += length; + if (inmark) markpos += length; } return length; }