Return-Path: Delivered-To: apmail-tomcat-dev-archive@www.apache.org Received: (qmail 16638 invoked from network); 4 Sep 2007 02:44:32 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 4 Sep 2007 02:44:32 -0000 Received: (qmail 11431 invoked by uid 500); 4 Sep 2007 02:44:26 -0000 Delivered-To: apmail-tomcat-dev-archive@tomcat.apache.org Received: (qmail 10503 invoked by uid 500); 4 Sep 2007 02:44:24 -0000 Mailing-List: contact dev-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Developers List" Delivered-To: mailing list dev@tomcat.apache.org Received: (qmail 10492 invoked by uid 500); 4 Sep 2007 02:44:24 -0000 Delivered-To: apmail-jakarta-tomcat-dev@jakarta.apache.org Received: (qmail 10489 invoked by uid 99); 4 Sep 2007 02:44:24 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Sep 2007 19:44:24 -0700 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 04 Sep 2007 02:44:28 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 89C111A983A; Mon, 3 Sep 2007 19:44:08 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r572497 - /tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/buf/B2CConverter.java Date: Tue, 04 Sep 2007 02:44:08 -0000 To: tomcat-dev@jakarta.apache.org From: billbarker@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20070904024408.89C111A983A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: billbarker Date: Mon Sep 3 19:44:07 2007 New Revision: 572497 URL: http://svn.apache.org/viewvc?rev=572497&view=rev Log: Forward porting Reader fixes from 5.5.x Modified: tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/buf/B2CConverter.java Modified: tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/buf/B2CConverter.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/buf/B2CConverter.java?rev=572497&r1=572496&r2=572497&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/buf/B2CConverter.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/buf/B2CConverter.java Mon Sep 3 19:44:07 2007 @@ -68,22 +68,31 @@ char result[]=new char[BUFFER_SIZE]; /** Convert a buffer of bytes into a chars + * @deprecated */ public void convert( ByteChunk bb, CharChunk cb ) throws IOException { // Set the ByteChunk as input to the Intermediate reader - iis.setByteChunk( bb ); - convert(cb); + convert(bb, cb, cb.getBuffer().length - cb.getEnd()); } - private void convert(CharChunk cb) + public void convert( ByteChunk bb, CharChunk cb, int limit) + throws IOException + { + iis.setByteChunk( bb ); + convert(cb, limit); + } + + private void convert(CharChunk cb, int limit) throws IOException { try { // read from the reader - while( true ) { // conv.ready() ) { - int cnt=conv.read( result, 0, BUFFER_SIZE ); + int count = 0; + while( limit > 0 ) { // conv.ready() ) { + int size = limit < BUFFER_SIZE ? limit : BUFFER_SIZE; + int cnt=conv.read( result, 0, size ); if( cnt <= 0 ) { // End of stream ! - we may be in a bad state if( debug>0) @@ -96,6 +105,7 @@ // XXX go directly cb.append( result, 0, cnt ); + limit -= cnt; } } catch( IOException ex) { if( debug>0) @@ -225,10 +235,7 @@ not be called if recycling the converter and if data was not flushed. */ final class IntermediateInputStream extends InputStream { - byte buf[]; - int pos; - int len; - int end; + ByteChunk bc = null; public IntermediateInputStream() { } @@ -239,36 +246,18 @@ } public final int read(byte cbuf[], int off, int len) throws IOException { - if( pos >= end ) return -1; - if (pos + len > end) { - len = end - pos; - } - if (len <= 0) { - return 0; - } - System.arraycopy(buf, pos, cbuf, off, len); - pos += len; - return len; + return bc.substract(cbuf, off, len); } public final int read() throws IOException { - return (pos < end ) ? (buf[pos++] & 0xff) : -1; + return bc.substract(); } // -------------------- Internal methods -------------------- - void setBuffer( byte b[], int p, int l ) { - buf=b; - pos=p; - len=l; - end=pos+len; - } void setByteChunk( ByteChunk mb ) { - buf=mb.getBytes(); - pos=mb.getStart(); - len=mb.getLength(); - end=pos+len; + bc = mb; } } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org For additional commands, e-mail: dev-help@tomcat.apache.org