Why does the implementation of the substract() methods of org.apache.tomcat.util.buf.ByteChunk.java (http://cvs.apache.org/viewcvs.cgi/jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/buf/ByteChunk.java?rev=1.24&view=markup) assume that in.realReadBytes will manipulate the start and end pointers of ByteChunk?

org.apache.coyote.http11.InternalInputBuffer.doRead [which gets invoked
along the realReadBytes codepath] calls ByteChunk.setBytes (which
initializes start, end etc) so the scenario below doesn't occur with the
coyote connector. Just wondering if this is a contract that other
buffering connector implementations must adhere to.

In the code below, when buff needs to be refilled (e.g. start = end =
buff.length = 8192), and if realReadBytes doesn't reset start to 0, then
buff[start++] results in an IndexOutOfBoundsException. The other
substract() variants have a similar issue.

   public int substract()
        throws IOException {

        if ((end - start) == 0) {
            if (in == null)
                return -1;
            int n = in.realReadBytes( buff, 0, buff.length );
            if (n < 0)
                return -1;
        }

        return (buff[start++] & 0xFF);

    }

I expected to see start, off and end rest in the substract() method itself.
   public int substract()
        throws IOException {

        if ((end - start) == 0) {
            if (in == null)
                return -1;
            int n = in.realReadBytes( buff, 0, buff.length );
>>>>        start = off = 0;
end = n;
        }

        return (buff[start++] & 0xFF);

    }



Thanks,
 Arvind


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to