Index: util/java/org/apache/tomcat/util/buf/B2CConverter.java =================================================================== --- util/java/org/apache/tomcat/util/buf/B2CConverter.java (revision 638800) +++ util/java/org/apache/tomcat/util/buf/B2CConverter.java (working copy) @@ -68,11 +68,12 @@ char result[]=new char[BUFFER_SIZE]; /** Convert a buffer of bytes into a chars + * @deprecated */ public void convert( ByteChunk bb, CharChunk cb ) throws IOException { - convert(bb, cb, cb.getBuffer().length - cb.getEnd()); + convert(bb, cb, cb.getLimit() - cb.getEnd()); } /** Convert a buffer of bytes into a chars @@ -90,7 +91,6 @@ { try { // read from the reader - int count = 0; while( limit > 0 ) { int size = limit < BUFFER_SIZE ? limit : BUFFER_SIZE; int cnt=conv.read( result, 0, size ); @@ -195,14 +195,15 @@ */ final class ReadConvertor extends InputStreamReader { - // Has a private, internal byte[8192] - + private IntermediateInputStream iis; + /** Create a converter. */ public ReadConvertor( IntermediateInputStream in, String enc ) throws UnsupportedEncodingException { super( in, enc ); + iis=in; } /** Overriden - will do nothing but reset internal state. @@ -219,9 +220,18 @@ return super.read( cbuf, off, len ); } - /** Reset the buffer + /* + * Reset the buffer */ public final void recycle() { + iis.recycle(); + try{ + // Must clear super's buffer. + while(ready()){ + // InputStreamReader#skip(long) will allocate buffer to skip. + read(); + } + }catch(IOException ioe){} } } @@ -244,21 +254,32 @@ } public final int read(byte cbuf[], int off, int len) throws IOException { - int nread = bc.substract(cbuf, off, len); - return nread; + if(bc == null){ + return -1; + } + return bc.substract(cbuf, off, len); } public final int read() throws IOException { + if(bc == null){ + return -1; + } return bc.substract(); } public int available() throws IOException { + if(bc == null){ + return 0; + } return bc.getLength(); } // -------------------- Internal methods -------------------- + void recycle(){ + bc = null; + } void setByteChunk( ByteChunk mb ) { bc = mb;