Index: catalina/src/share/org/apache/catalina/connector/CoyoteReader.java =================================================================== --- catalina/src/share/org/apache/catalina/connector/CoyoteReader.java (revision 638800) +++ catalina/src/share/org/apache/catalina/connector/CoyoteReader.java (working copy) @@ -119,7 +119,7 @@ public boolean markSupported() { - return true; + return ib.markSupported(); } Index: catalina/src/share/org/apache/catalina/connector/InputBuffer.java =================================================================== --- catalina/src/share/org/apache/catalina/connector/InputBuffer.java (revision 638800) +++ catalina/src/share/org/apache/catalina/connector/InputBuffer.java (working copy) @@ -227,15 +227,14 @@ } - public int available() - throws IOException { + public int available() { + int available = 0; if (state == BYTE_STATE) { - return bb.getLength(); + available = bb.getLength(); } else if (state == CHAR_STATE) { - return cb.getLength(); - } else { - return 0; + available = cb.getLength(); } + return available; } @@ -308,21 +307,29 @@ if (!gotEnc) setConverter(); + int nRead = 0; if (bb.getLength() <= 0) { - int nRead = realReadBytes(bb.getBytes(), 0, bb.getBytes().length); - if (nRead < 0) { - return -1; - } + nRead = realReadBytes(bb.getBytes(), 0, bb.getBytes().length); + // Data may be remaining in the buffer of ReadConverter('s super). + // So we must try to convert whether nRead is positive or not. } - if (markPos == -1) { cb.setOffset(0); cb.setEnd(0); } + + if((markPos >= 0) && (cb.getLimit()-cb.getEnd()) <= 0){ + // markPos will be reset and the status of cb will be modified + // via cb.flushBuffer(), only if more chars exists. + conv.convert(bb, cb, cb.getLimit()); + }else{ + conv.convert(bb, cb, cb.getLimit()-cb.getEnd()); + } state = CHAR_STATE; - conv.convert(bb, cb, len); - bb.setOffset(bb.getEnd()); + if((nRead < 0) && (cb.getLength()==0)){ + return -1; + } return cb.getLength(); } @@ -380,7 +387,7 @@ public boolean ready() throws IOException { - return (cb.getLength() > 0); + return (available() > 0); } @@ -391,6 +398,9 @@ public void mark(int readAheadLimit) throws IOException { + if (readAheadLimit < 0){ // See BufferedReader#mark(int) JavaDoc + throw new IllegalArgumentException("readAheadLimit value is negative"); + } if (cb.getLength() <= 0) { cb.setOffset(0); cb.setEnd(0); @@ -416,9 +426,7 @@ throws IOException { if (state == CHAR_STATE) { if (markPos < 0) { - cb.recycle(); - markPos = -1; - throw new IOException(); + throw new IOException("The mark is not effective"); } else { cb.setOffset(markPos); }