You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Arvind Srinivasan <ar...@Sun.COM> on 2005/05/12 11:41:50 UTC
Question about ByteChunk.substract implementation
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: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org