You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@apache.org on 2004/03/05 14:04:24 UTC
cvs commit: jakarta-tomcat-catalina/catalina/src/share/org/apache/coyote/tomcat5 InputBuffer.java
remm 2004/03/05 05:04:24
Modified: catalina/src/share/org/apache/coyote/tomcat5
InputBuffer.java
Log:
- Fix mark/reset functionality.
- It is valid to reset more than once.
- If the buffer was grown, discard and reallocate (mark can make the buffer
grow a lot, which is a valid use case).
- If the buffer is empty when marking, reinit it (to avoid it growing more than it
should).
Revision Changes Path
1.5 +21 -3 jakarta-tomcat-catalina/catalina/src/share/org/apache/coyote/tomcat5/InputBuffer.java
Index: InputBuffer.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/coyote/tomcat5/InputBuffer.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- InputBuffer.java 27 Feb 2004 14:58:53 -0000 1.4
+++ InputBuffer.java 5 Mar 2004 13:04:24 -0000 1.5
@@ -139,6 +139,12 @@
private int markPos = -1;
+ /**
+ * Buffer size.
+ */
+ private int size = -1;
+
+
// ----------------------------------------------------------- Constructors
@@ -159,6 +165,7 @@
*/
public InputBuffer(int size) {
+ this.size = size;
bb = new ByteChunk(size);
bb.setLimit(size);
bb.setByteInputChannel(this);
@@ -208,7 +215,15 @@
bytesRead = 0;
charsRead = 0;
- cb.recycle();
+ // If usage of mark made the buffer too big, reallocate it
+ if (cb.getChars().length > size) {
+ cb = new CharChunk(size);
+ cb.setLimit(size);
+ cb.setCharInputChannel(this);
+ cb.setCharOutputChannel(this);
+ } else {
+ cb.recycle();
+ }
markPos = -1;
bb.recycle();
closed = false;
@@ -406,7 +421,11 @@
public void mark(int readAheadLimit)
throws IOException {
- cb.setLimit(cb.getEnd() + readAheadLimit);
+ if (cb.getLength() <= 0) {
+ cb.setOffset(0);
+ cb.setEnd(0);
+ }
+ cb.setLimit(cb.getStart() + readAheadLimit);
markPos = cb.getStart();
}
@@ -420,7 +439,6 @@
throw new IOException();
} else {
cb.setOffset(markPos);
- markPos = -1;
}
} else {
bb.recycle();
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org