Remy Maucherat wrote: > > I can't see why. Is my interpretation on what will happen at the next > iteration wrong ? > You are perfectly right. Sorry, I misunderstood the loop (didn't realize the pos=0 after the read()). A problem could only arrise if somewhere else a mark is set before your functions, then pos=0 would set the wrong position. But marks are not used anywhere so this won't be a problem. > > Especially since we don't care about marking here. I attached a little patch that reimplements the used methods of the BIS. It should be a little bit faster because it doesn't implement marks. Not sure if it is worth the extra code because read() isn't called very often anyway and if read(byte []) is used anywhere then it should be rewritten too (didn't do it here because I wasn't sure if it is ever used). -- Thomas Butter <[EMAIL PROTECTED]> ICQ: 891617 "Unix IS user friendly, it is just selective about who his friends are."
--- SocketInputStream.java.orig Thu Jan 11 09:18:45 2001 +++ SocketInputStream.java Thu Jan 11 10:14:41 2001 @@ -65,7 +65,7 @@ package org.apache.catalina.connector.http; import java.io.IOException; -import java.io.BufferedInputStream; +import java.io.FilterInputStream; import java.io.InputStream; import java.io.EOFException; import org.apache.catalina.util.StringManager; @@ -76,7 +76,7 @@ * * @author <a href="mailto:[EMAIL PROTECTED]">Remy Maucherat</a> */ -public class SocketInputStream extends BufferedInputStream { +public class SocketInputStream extends FilterInputStream { // -------------------------------------------------------------- Constants @@ -112,8 +112,54 @@ private static final int LC_OFFSET = 'A' - 'a'; - // ----------------------------------------------------------- Constructors + // BufferInputStream rewrite without marks + private byte buf[]; + private int count=0; + private int pos=0; + + public void close() throws IOException { + if(in!=null) in.close(); + in=null; + buf=null; + } + + public synchronized int available() throws IOException { + if(in==null) + throw (new IOException("Stream was closed")); + return (count-pos)+in.available(); + } + + public synchronized int read() + throws IOException + { + if(in==null) + throw (new IOException("Stream was closed")); + if(pos>=count) { + pos=0; + count=in.read(buf); + if(count<=0) return -1; + } + + return buf[pos++] & 0xff; + } + + public synchronized long skip(long n) throws IOException { + if(in==null) + throw (new IOException("Stream was closed")); + long skipped=0; + if(n<=0) return 0; + if(n>count-pos) { + skipped=count-pos; + n-=skipped; + pos=count; + skipped+=in.skip(n); + } else { + skipped=n; + count+=n; + } + return skipped; + } /** * Construct a servlet input stream associated with the specified socket @@ -123,9 +169,9 @@ * @param bufferSize size of the internal buffer */ public SocketInputStream(InputStream is, int bufferSize) { - - super(is, bufferSize); - + super(is); + if(bufferSize<=0) bufferSize=1024; // switch back to default + buf=new byte[bufferSize]; }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, email: [EMAIL PROTECTED]