Author: billbarker
Date: Sun Aug 26 20:38:45 2007
New Revision: 569970

URL: http://svn.apache.org/viewvc?rev=569970&view=rev
Log:
Change B2C to only add up to the limit on the CB, and use the sinks to the BC 
to request all data.  

Modified:
    
tomcat/connectors/trunk/util/java/org/apache/tomcat/util/buf/B2CConverter.java
    tomcat/connectors/trunk/util/java/org/apache/tomcat/util/buf/CharChunk.java

Modified: 
tomcat/connectors/trunk/util/java/org/apache/tomcat/util/buf/B2CConverter.java
URL: 
http://svn.apache.org/viewvc/tomcat/connectors/trunk/util/java/org/apache/tomcat/util/buf/B2CConverter.java?rev=569970&r1=569969&r2=569970&view=diff
==============================================================================
--- 
tomcat/connectors/trunk/util/java/org/apache/tomcat/util/buf/B2CConverter.java 
(original)
+++ 
tomcat/connectors/trunk/util/java/org/apache/tomcat/util/buf/B2CConverter.java 
Sun Aug 26 20:38:45 2007
@@ -72,18 +72,28 @@
     public  void convert( ByteChunk bb, CharChunk cb )
         throws IOException
     {
+        convert(bb, cb, cb.getBuff().length - cb.getEnd());
+    }
+
+    /** Convert a buffer of bytes into a chars
+     */
+    public  void convert( ByteChunk bb, CharChunk cb, int limit)
+        throws IOException
+    {
         // Set the ByteChunk as input to the Intermediate reader
         iis.setByteChunk( bb );
-        convert(cb);
+        convert(cb, limit);
     }
 
-    private void convert(CharChunk cb)
+    private void convert(CharChunk cb, int limit)
         throws IOException
     {
         try {
             // read from the reader
-            while( iis.available()>0 ) { // conv.ready() ) {
-                int cnt=conv.read( result, 0, BUFFER_SIZE );
+            int count = 0;
+            while( limit > 0 ) { 
+                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 +106,7 @@
 
                 // XXX go directly
                 cb.append( result, 0, cnt );
+                limit -= cnt;
             }
         } catch( IOException ex) {
             if( debug>0)
@@ -222,10 +233,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() {
     }
@@ -236,41 +244,24 @@
     }
     
     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;
+        int nread = bc.substract(cbuf, off, len);
+        return nread;
     }
     
     public  final int read() throws IOException {
-        return (pos < end ) ? (buf[pos++] & 0xff) : -1;
+        return bc.substract();
     }
     
     public int available() throws IOException {
-        return end-pos;
+        return bc.getLength();
     }
 
 
     // -------------------- 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;
     }
 
 }

Modified: 
tomcat/connectors/trunk/util/java/org/apache/tomcat/util/buf/CharChunk.java
URL: 
http://svn.apache.org/viewvc/tomcat/connectors/trunk/util/java/org/apache/tomcat/util/buf/CharChunk.java?rev=569970&r1=569969&r2=569970&view=diff
==============================================================================
--- tomcat/connectors/trunk/util/java/org/apache/tomcat/util/buf/CharChunk.java 
(original)
+++ tomcat/connectors/trunk/util/java/org/apache/tomcat/util/buf/CharChunk.java 
Sun Aug 26 20:38:45 2007
@@ -293,12 +293,15 @@
             System.arraycopy(src, off+avail, buff, end, len - avail);
             end+= len - avail;
             
-        } else {        // len > buf.length + avail
+        } else if(optimizedWrite) { // len > buf.length + avail & we have a 
real sink
             // long write - flush the buffer and write the rest
             // directly from source
             flushBuffer();
             
             out.realWriteChars( src, off, len );
+        } else { // ugly but it works for fake sinks if they reset us
+            flushBuffer();
+            append(src, off, len);
         }
     }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to