You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by kk...@apache.org on 2011/11/10 07:24:07 UTC

svn commit: r1200181 - in /tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/buf: ByteChunk.java C2BConverter.java CharChunk.java

Author: kkolinko
Date: Thu Nov 10 06:24:07 2011
New Revision: 1200181

URL: http://svn.apache.org/viewvc?rev=1200181&view=rev
Log:
Merged revision 1187753 from tomcat/trunk:
Clean-up. No functional change.
Part 7.

Modified:
    tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/buf/ByteChunk.java
    tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/buf/C2BConverter.java
    tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/buf/CharChunk.java

Modified: tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/buf/ByteChunk.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/buf/ByteChunk.java?rev=1200181&r1=1200180&r2=1200181&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/buf/ByteChunk.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/buf/ByteChunk.java Thu Nov 10 06:24:07 2011
@@ -14,7 +14,6 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-
 package org.apache.tomcat.util.buf;
 
 import java.io.IOException;
@@ -75,9 +74,9 @@ public final class ByteChunk implements 
      * Same as java.nio.channel.ReadableByteChannel
      */
     public static interface ByteInputChannel {
-        /** 
+        /**
          * Read new bytes ( usually the internal conversion buffer ).
-         * The implementation is allowed to ignore the parameters, 
+         * The implementation is allowed to ignore the parameters,
          * and mutate the chunk if it wishes to implement its own buffering.
          */
         public int realReadBytes(byte cbuf[], int off, int len)
@@ -87,7 +86,7 @@ public final class ByteChunk implements 
     /** Same as java.nio.channel.WrittableByteChannel.
      */
     public static interface ByteOutputChannel {
-        /** 
+        /**
          * Send the bytes ( usually the internal conversion buffer ).
          * Expect 8k output if the buffer is full.
          */
@@ -99,10 +98,10 @@ public final class ByteChunk implements 
 
     /** Default encoding used to convert to strings. It should be UTF8,
         as most standards seem to converge, but the servlet API requires
-        8859_1, and this object is used mostly for servlets. 
+        8859_1, and this object is used mostly for servlets.
     */
     public static final Charset DEFAULT_CHARSET;
-        
+
     static {
         Charset c = null;
         try {
@@ -130,7 +129,7 @@ public final class ByteChunk implements 
     private ByteOutputChannel out = null;
 
     private boolean optimizedWrite=true;
-    
+
     /**
      * Creates a new, uninitialized ByteChunk object.
      */
@@ -154,7 +153,7 @@ public final class ByteChunk implements 
     public boolean isNull() {
         return ! isSet; // buff==null;
     }
-    
+
     /**
      * Resets the message buff to an uninitialized state.
      */
@@ -175,7 +174,7 @@ public final class ByteChunk implements 
     public void allocate( int initial, int limit  ) {
         if( buff==null || buff.length < initial ) {
             buff=new byte[initial];
-        }    
+        }
         this.limit=limit;
         start=0;
         end=0;
@@ -184,7 +183,7 @@ public final class ByteChunk implements 
 
     /**
      * Sets the message bytes to the specified subarray of bytes.
-     * 
+     *
      * @param b the ascii bytes
      * @param off the start offset of the bytes
      * @param len the length of the bytes
@@ -238,7 +237,9 @@ public final class ByteChunk implements 
     }
 
     public void setOffset(int off) {
-        if (end < off ) end=off;
+        if (end < off ) {
+            end=off;
+        }
         start=off;
     }
 
@@ -260,7 +261,7 @@ public final class ByteChunk implements 
     public void setLimit(int limit) {
         this.limit=limit;
     }
-    
+
     public int getLimit() {
         return limit;
     }
@@ -385,11 +386,13 @@ public final class ByteChunk implements 
         throws IOException {
 
         if ((end - start) == 0) {
-            if (in == null)
+            if (in == null) {
                 return -1;
+            }
             int n = in.realReadBytes( buff, 0, buff.length );
-            if (n < 0)
+            if (n < 0) {
                 return -1;
+            }
         }
 
         return (buff[start++] & 0xFF);
@@ -400,11 +403,13 @@ public final class ByteChunk implements 
         throws IOException {
 
         if ((end - start) == 0) {
-            if (in == null)
+            if (in == null) {
                 return -1;
+            }
             int n = in.realReadBytes( buff, 0, buff.length );
-            if (n < 0)
+            if (n < 0) {
                 return -1;
+            }
         }
 
         int len = getLength();
@@ -418,11 +423,13 @@ public final class ByteChunk implements 
         throws IOException {
 
         if ((end - start) == 0) {
-            if (in == null)
+            if (in == null) {
                 return -1;
+            }
             int n = in.realReadBytes( buff, 0, buff.length );
-            if (n < 0)
+            if (n < 0) {
                 return -1;
+            }
         }
 
         int n = len;
@@ -471,10 +478,13 @@ public final class ByteChunk implements 
         }
 
         if( buff==null ) {
-            if( desiredSize < 256 ) desiredSize=256; // take a minimum
+            if( desiredSize < 256 )
+             {
+                desiredSize=256; // take a minimum
+            }
             buff=new byte[desiredSize];
         }
-        
+
         // limit < buf.length ( the buffer is already big )
         // or we already have space XXX
         if( desiredSize <= buff.length ) {
@@ -484,22 +494,26 @@ public final class ByteChunk implements 
         if( desiredSize < 2 * buff.length ) {
             newSize= buff.length * 2;
             if( limit >0 &&
-                newSize > limit ) newSize=limit;
+                newSize > limit ) {
+                newSize=limit;
+            }
             tmp=new byte[newSize];
         } else {
             newSize= buff.length * 2 + count ;
             if( limit > 0 &&
-                newSize > limit ) newSize=limit;
+                newSize > limit ) {
+                newSize=limit;
+            }
             tmp=new byte[newSize];
         }
-        
+
         System.arraycopy(buff, start, tmp, 0, end-start);
         buff = tmp;
         tmp = null;
         end=end-start;
         start=0;
     }
-    
+
     // -------------------- Conversion and getters --------------------
 
     @Override
@@ -511,7 +525,7 @@ public final class ByteChunk implements 
         }
         return StringCache.toString(this);
     }
-    
+
     public String toStringInternal() {
         if (charset == null) {
             charset = DEFAULT_CHARSET;
@@ -544,7 +558,7 @@ public final class ByteChunk implements 
     public boolean equals(String s) {
         // XXX ENCODING - this only works if encoding is UTF8-compat
         // ( ok for tomcat, where we compare ascii - header names, etc )!!!
-        
+
         byte[] b = buff;
         int blen = end-start;
         if (b == null || blen != s.length()) {
@@ -582,15 +596,18 @@ public final class ByteChunk implements 
     public boolean equals( ByteChunk bb ) {
         return equals( bb.getBytes(), bb.getStart(), bb.getLength());
     }
-    
+
     public boolean equals( byte b2[], int off2, int len2) {
         byte b1[]=buff;
-        if( b1==null && b2==null ) return true;
+        if( b1==null && b2==null ) {
+            return true;
+        }
 
         int len=end-start;
-        if ( len2 != len || b1==null || b2==null ) 
+        if ( len2 != len || b1==null || b2==null ) {
             return false;
-                
+        }
+
         int off1 = start;
 
         while ( len-- > 0) {
@@ -604,18 +621,20 @@ public final class ByteChunk implements 
     public boolean equals( CharChunk cc ) {
         return equals( cc.getChars(), cc.getStart(), cc.getLength());
     }
-    
+
     public boolean equals( char c2[], int off2, int len2) {
         // XXX works only for enc compatible with ASCII/UTF !!!
         byte b1[]=buff;
-        if( c2==null && b1==null ) return true;
-        
+        if( c2==null && b1==null ) {
+            return true;
+        }
+
         if (b1== null || c2==null || end-start != len2 ) {
             return false;
         }
         int off1 = start;
         int len=end-start;
-        
+
         while ( len-- > 0) {
             if ( (char)b1[off1++] != c2[off2++]) {
                 return false;
@@ -656,8 +675,9 @@ public final class ByteChunk implements 
             return false;
         }
         for (int i = start, j = 0; i < end && j < b2.length;) {
-            if (b1[i++] != b2[j++]) 
+            if (b1[i++] != b2[j++]) {
                 return false;
+            }
         }
         return true;
     }
@@ -685,17 +705,20 @@ public final class ByteChunk implements 
     public int indexOf( String src, int srcOff, int srcLen, int myOff ) {
         char first=src.charAt( srcOff );
 
-        // Look for first char 
+        // Look for first char
         int srcEnd = srcOff + srcLen;
-        
+
         mainLoop:
         for( int i=myOff+start; i <= (end - srcLen); i++ ) {
-            if( buff[i] != first ) continue;
+            if( buff[i] != first ) {
+                continue;
+            }
             // found first char, now look for a match
             int myPos=i+1;
             for( int srcPos=srcOff + 1; srcPos< srcEnd;) {
-                if( buff[myPos++] != src.charAt( srcPos++ ))
+                if( buff[myPos++] != src.charAt( srcPos++ )) {
                     continue mainLoop;
+                }
             }
             return i-start; // found it
         }
@@ -704,7 +727,7 @@ public final class ByteChunk implements 
 
     // -------------------- Hash code  --------------------
 
-    // normal hash. 
+    // normal hash.
     public int hash() {
         return hashBytes( buff, start, end-start);
     }
@@ -742,7 +765,7 @@ public final class ByteChunk implements 
      * returned.
      * <br/>
      * NOTE: This only works for characters in the range 0-127.
-     * 
+     *
      * @param c         The character
      * @param starting  The start position
      * @return          The position of the first instance of the character or
@@ -758,21 +781,22 @@ public final class ByteChunk implements 
      * between the specified start and end.
      * <br/>
      * NOTE: This only works for characters in the range 0-127.
-     * 
+     *
      * @param bytes The byte array to search
      * @param start The point to start searching from in the byte array
      * @param end   The point to stop searching in the byte array
-     * @param c     The character to search for 
+     * @param c     The character to search for
      * @return      The position of the first instance of the character or -1
      *                  if the character is not found.
      */
     public static int indexOf(byte bytes[], int start, int end, char c) {
         int offset = start;
-        
+
         while (offset < end) {
             byte b=bytes[offset];
-            if (b == c)
+            if (b == c) {
                 return offset;
+            }
             offset++;
         }
         return -1;
@@ -781,11 +805,11 @@ public final class ByteChunk implements 
     /**
      * Returns the first instance of the given byte in the byte array between
      * the specified start and end.
-     * 
+     *
      * @param bytes The byte array to search
      * @param start The point to start searching from in the byte array
      * @param end   The point to stop searching in the byte array
-     * @param b     The byte to search for 
+     * @param b     The byte to search for
      * @return      The position of the first instance of the byte or -1 if the
      *                  byte is not found.
      */
@@ -803,11 +827,11 @@ public final class ByteChunk implements 
     /**
      * Returns the first instance of any of the given bytes in the byte array
      * between the specified start and end.
-     * 
+     *
      * @param bytes The byte array to search
      * @param start The point to start searching from in the byte array
      * @param end   The point to stop searching in the byte array
-     * @param b     The array of bytes to search for 
+     * @param b     The array of bytes to search for
      * @return      The position of the first instance of the byte or -1 if the
      *                  byte is not found.
      */
@@ -815,10 +839,11 @@ public final class ByteChunk implements 
         int blen = b.length;
         int offset = start;
         while (offset < end) {
-            for (int i = 0;  i < blen; i++) 
+            for (int i = 0;  i < blen; i++) {
                 if (bytes[offset] == b[i]) {
                     return offset;
                 }
+            }
             offset++;
         }
         return -1;
@@ -827,11 +852,11 @@ public final class ByteChunk implements 
     /**
      * Returns the first instance of any byte that is not one of the given bytes
      * in the byte array between the specified start and end.
-     * 
+     *
      * @param bytes The byte array to search
      * @param start The point to start searching from in the byte array
      * @param end   The point to stop searching in the byte array
-     * @param b     The list of bytes to search for 
+     * @param b     The list of bytes to search for
      * @return      The position of the first instance a byte that is not
      *                  in the list of bytes to search for or -1 if no such byte
      *                  is found.
@@ -840,7 +865,7 @@ public final class ByteChunk implements 
         int blen = b.length;
         int offset = start;
         boolean found;
-                
+
         while (offset < end) {
             found = true;
             for (int i = 0; i < blen; i++) {
@@ -861,7 +886,7 @@ public final class ByteChunk implements 
     /**
      * Convert specified String to a byte array. This ONLY WORKS for ascii, UTF
      * chars will be truncated.
-     * 
+     *
      * @param value to convert to byte array
      * @return the byte array value
      */

Modified: tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/buf/C2BConverter.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/buf/C2BConverter.java?rev=1200181&r1=1200180&r2=1200181&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/buf/C2BConverter.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/buf/C2BConverter.java Thu Nov 10 06:24:07 2011
@@ -14,7 +14,6 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-
 package org.apache.tomcat.util.buf;
 
 import java.io.IOException;
@@ -23,22 +22,22 @@ import java.io.OutputStreamWriter;
 import java.nio.charset.Charset;
 
 /** Efficient conversion of character to bytes.
- *  
+ *
  *  This uses the standard JDK mechanism - a writer - but provides mechanisms
  *  to recycle all the objects that are used. It is compatible with JDK1.1 and up,
  *  ( nio is better, but it's not available even in 1.2 or 1.3 )
- * 
+ *
  */
 public final class C2BConverter {
-    
+
     private static final org.apache.juli.logging.Log log=
         org.apache.juli.logging.LogFactory.getLog(C2BConverter.class );
-    
-    private IntermediateOutputStream ios;
-    private WriteConvertor conv;
+
+    private final IntermediateOutputStream ios;
+    private final WriteConvertor conv;
     private ByteChunk bb;
-    private String enc;
-    
+    private final String enc;
+
     /** Create a converter, with bytes going to a byte buffer
      */
     public C2BConverter(ByteChunk output, String encoding) throws IOException {
@@ -103,13 +102,14 @@ public final class C2BConverter {
      */
     public final void convert(MessageBytes mb ) throws IOException {
         int type=mb.getType();
-        if( type==MessageBytes.T_BYTES )
+        if( type==MessageBytes.T_BYTES ) {
             return;
+        }
         ByteChunk orig=bb;
         setByteChunk( mb.getByteChunk());
         bb.recycle();
         bb.allocate( 32, -1 );
-        
+
         if( type==MessageBytes.T_STR ) {
             convert( mb.getString() );
             // System.out.println("XXX Converting " + mb.getString() );
@@ -119,11 +119,12 @@ public final class C2BConverter {
                                 charC.getOffset(), charC.getLength());
             //System.out.println("XXX Converting " + mb.getCharChunk() );
         } else {
-            if (log.isDebugEnabled())
+            if (log.isDebugEnabled()) {
                 log.debug("XXX unknowon type " + type );
+            }
         }
         flushBuffer();
-        //System.out.println("C2B: XXX " + bb.getBuffer() + bb.getLength()); 
+        //System.out.println("C2B: XXX " + bb.getBuffer() + bb.getLength());
         setByteChunk(orig);
     }
 
@@ -142,13 +143,13 @@ public final class C2BConverter {
 
 /**
  *  Special writer class, where close() is overridden. The default implementation
- *  would set byteOutputter to null, and the writer can't be recycled. 
+ *  would set byteOutputter to null, and the writer can't be recycled.
  *
  *  Note that the flush method will empty the internal buffers _and_ call
  *  flush on the output stream - that's why we use an intermediary output stream
  *  that overrides flush(). The idea is to  have full control: flushing the
  *  char->byte converter should be independent of flushing the OutputStream.
- * 
+ *
  *  When a WriteConverter is created, it'll allocate one or 2 byte buffers,
  *  with a 8k size that can't be changed ( at least in JDK1.1 -> 1.4 ). It would
  *  also allocate a ByteOutputter or equivalent - again some internal buffers.
@@ -156,23 +157,23 @@ public final class C2BConverter {
  *  It is essential to keep  this object around and reuse it. You can use either
  *  pools or per thread data - but given that in most cases a converter will be
  *  needed for every thread and most of the time only 1 ( or 2 ) encodings will
- *  be used, it is far better to keep it per thread and eliminate the pool 
+ *  be used, it is far better to keep it per thread and eliminate the pool
  *  overhead too.
- * 
+ *
  */
  final class WriteConvertor extends OutputStreamWriter {
     // stream with flush() and close(). overridden.
-    private IntermediateOutputStream ios;
-    
+    private final IntermediateOutputStream ios;
+
     // Has a private, internal byte[8192]
-    
+
     /** Create a converter.
      */
     public WriteConvertor(IntermediateOutputStream out, Charset charset) {
         super(out, charset);
         ios=out;
     }
-    
+
     /** Overridden - will do nothing but reset internal state.
      */
     @Override
@@ -180,23 +181,23 @@ public final class C2BConverter {
         // NOTHING
         // Calling super.close() would reset out and cb.
     }
-    
+
     /**
      *  Flush the characters only
-     */ 
+     */
     @Override
     public  final void flush() throws IOException {
         // Will flushBuffer and out()
-        // flushBuffer put any remaining chars in the byte[] 
+        // flushBuffer put any remaining chars in the byte[]
         super.flush();
     }
-    
+
     @Override
     public  final void write(char cbuf[], int off, int len) throws IOException {
         // will do the conversion and call write on the output stream
         super.write( cbuf, off, len );
     }
-    
+
     /** Reset the buffer
      */
     public  final void recycle() {
@@ -209,36 +210,36 @@ public final class C2BConverter {
         }
         ios.enable();
     }
-    
+
 }
 
 
 /** Special output stream where close() is overridden, so super.close()
     is never called.
-    
+
     This allows recycling. It can also be disabled, so callbacks will
     not be called if recycling the converter and if data was not flushed.
 */
 final class IntermediateOutputStream extends OutputStream {
     private ByteChunk tbuff;
     private boolean enabled=true;
-    
+
     public IntermediateOutputStream(ByteChunk tbuff) {
         this.tbuff=tbuff;
     }
-    
+
     @Override
     public  final void close() throws IOException {
         // shouldn't be called - we filter it out in writer
         throw new IOException("close() called - shouldn't happen ");
     }
-    
+
     @Override
     public  final void flush() throws IOException {
         // nothing - write will go directly to the buffer,
         // we don't keep any state
     }
-    
+
     @Override
     public  final  void write(byte cbuf[], int off, int len) throws IOException {
         // will do the conversion and call write on the output stream
@@ -246,7 +247,7 @@ final class IntermediateOutputStream ext
             tbuff.append( cbuf, off, len );
         }
     }
-    
+
     @Override
     public  final void write( int i ) throws IOException {
         throw new IOException("write( int ) called - shouldn't happen ");
@@ -257,7 +258,7 @@ final class IntermediateOutputStream ext
     void setByteChunk( ByteChunk bb ) {
         tbuff=bb;
     }
-    
+
     /** Temporary disable - this is used to recycle the converter without
      *  generating an output if the buffers were not flushed
      */

Modified: tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/buf/CharChunk.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/buf/CharChunk.java?rev=1200181&r1=1200180&r2=1200181&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/buf/CharChunk.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/buf/CharChunk.java Thu Nov 10 06:24:07 2011
@@ -14,7 +14,6 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-
 package org.apache.tomcat.util.buf;
 
 import java.io.IOException;
@@ -25,7 +24,7 @@ import java.io.Serializable;
  * the easiest way to manipulate chars ( search, substrings, etc),
  * it is known to not be the most efficient solution - Strings are
  * designed as immutable and secure objects.
- * 
+ *
  * @author dac@sun.com
  * @author James Todd [gonzo@sun.com]
  * @author Costin Manolache
@@ -37,9 +36,9 @@ public final class CharChunk implements 
 
     // Input interface, used when the buffer is emptied.
     public static interface CharInputChannel {
-        /** 
+        /**
          * Read new bytes ( usually the internal conversion buffer ).
-         * The implementation is allowed to ignore the parameters, 
+         * The implementation is allowed to ignore the parameters,
          * and mutate the chunk if it wishes to implement its own buffering.
          */
         public int realReadChars(char cbuf[], int off, int len)
@@ -56,15 +55,15 @@ public final class CharChunk implements 
         public void realWriteChars(char cbuf[], int off, int len)
             throws IOException;
     }
-    
-    // -------------------- 
+
+    // --------------------
     // char[]
     private char buff[];
 
     private int start;
     private int end;
 
-    private boolean isSet=false;  // XXX 
+    private boolean isSet=false;  // XXX
 
     // -1: grow indefinitely
     // maximum amount to be cached
@@ -72,7 +71,7 @@ public final class CharChunk implements 
 
     private CharInputChannel in = null;
     private CharOutputChannel out = null;
-    
+
     private boolean optimizedWrite=true;
 
     /**
@@ -86,7 +85,7 @@ public final class CharChunk implements 
     }
 
     // --------------------
-    
+
     public CharChunk getClone() {
         try {
             return (CharChunk)this.clone();
@@ -96,10 +95,12 @@ public final class CharChunk implements 
     }
 
     public boolean isNull() {
-        if( end > 0 ) return false;
-        return !isSet; //XXX 
+        if( end > 0 ) {
+            return false;
+        }
+        return !isSet; //XXX
     }
-    
+
     /**
      * Resets the message bytes to an uninitialized state.
      */
@@ -148,7 +149,7 @@ public final class CharChunk implements 
     public void setLimit(int limit) {
         this.limit=limit;
     }
-    
+
     public int getLimit() {
         return limit;
     }
@@ -169,17 +170,17 @@ public final class CharChunk implements 
         this.out=out;
     }
 
-    // compat 
+    // compat
     public char[] getChars()
     {
         return getBuffer();
     }
-    
+
     public char[] getBuffer()
     {
         return buff;
     }
-    
+
     /**
      * Returns the start offset of the bytes.
      * For output this is the end of the buffer.
@@ -187,7 +188,7 @@ public final class CharChunk implements 
     public int getStart() {
         return start;
     }
-    
+
     public int getOffset() {
         return start;
     }
@@ -216,7 +217,7 @@ public final class CharChunk implements 
     }
 
     // -------------------- Adding data --------------------
-    
+
     public void append( char b )
         throws IOException
     {
@@ -228,7 +229,7 @@ public final class CharChunk implements 
         }
         buff[end++]=b;
     }
-    
+
     public void append( CharChunk src )
         throws IOException
     {
@@ -258,13 +259,13 @@ public final class CharChunk implements 
             out.realWriteChars( src, off, len );
             return;
         }
-        
+
         // if we have limit and we're below
         if( len <= limit - end ) {
             // makeSpace will grow the buffer to the limit,
             // so we have space
             System.arraycopy( src, off, buff, end, len );
-            
+
             end+=len;
             return;
         }
@@ -273,7 +274,7 @@ public final class CharChunk implements 
         // buffer
 
         // the buffer is already at ( or bigger than ) limit
-        
+
         // Optimization:
         // If len-avail < length ( i.e. after we fill the buffer with
         // what we can, the remaining will fit in the buffer ) we'll just
@@ -289,17 +290,17 @@ public final class CharChunk implements 
             int avail=limit-end;
             System.arraycopy(src, off, buff, end, avail);
             end += avail;
-            
+
             flushBuffer();
-            
+
             System.arraycopy(src, off+avail, buff, end, len - avail);
             end+= len - avail;
-            
+
         } else {        // len > buf.length + avail
             // long write - flush the buffer and write the rest
             // directly from source
             flushBuffer();
-            
+
             out.realWriteChars( src, off, len );
         }
     }
@@ -331,8 +332,9 @@ public final class CharChunk implements 
             sb.getChars( sbOff, sbOff+d, buff, end);
             sbOff += d;
             end += d;
-            if (end >= limit)
+            if (end >= limit) {
                 flushBuffer();
+            }
         }
     }
 
@@ -341,12 +343,14 @@ public final class CharChunk implements 
     public void append(String s) throws IOException {
         append(s, 0, s.length());
     }
-    
+
     /** Append a string to the buffer
      */
     public void append(String s, int off, int len) throws IOException {
-        if (s==null) return;
-        
+        if (s==null) {
+            return;
+        }
+
         // will grow, up to limit
         makeSpace( len );
 
@@ -365,22 +369,25 @@ public final class CharChunk implements 
             s.getChars( sOff, sOff+d, buff, end);
             sOff += d;
             end += d;
-            if (end >= limit)
+            if (end >= limit) {
                 flushBuffer();
+            }
         }
     }
-    
+
     // -------------------- Removing data from the buffer --------------------
 
     public int substract()
         throws IOException {
 
         if ((end - start) == 0) {
-            if (in == null)
+            if (in == null) {
                 return -1;
+            }
             int n = in.realReadChars(buff, end, buff.length - end);
-            if (n < 0)
+            if (n < 0) {
                 return -1;
+            }
         }
 
         return (buff[start++]);
@@ -391,11 +398,13 @@ public final class CharChunk implements 
         throws IOException {
 
         if ((end - start) == 0) {
-            if (in == null)
+            if (in == null) {
                 return -1;
+            }
             int n = in.realReadChars( buff, end, buff.length - end);
-            if (n < 0)
+            if (n < 0) {
                 return -1;
+            }
         }
 
         int len = getLength();
@@ -409,11 +418,13 @@ public final class CharChunk implements 
         throws IOException {
 
         if ((end - start) == 0) {
-            if (in == null)
+            if (in == null) {
                 return -1;
+            }
             int n = in.realReadChars( buff, end, buff.length - end);
-            if (n < 0)
+            if (n < 0) {
                 return -1;
+            }
         }
 
         int n = len;
@@ -456,7 +467,10 @@ public final class CharChunk implements 
         }
 
         if( buff==null ) {
-            if( desiredSize < 256 ) desiredSize=256; // take a minimum
+            if( desiredSize < 256 )
+             {
+                desiredSize=256; // take a minimum
+            }
             buff=new char[desiredSize];
         }
 
@@ -469,20 +483,24 @@ public final class CharChunk implements 
         if( desiredSize < 2 * buff.length ) {
             newSize= buff.length * 2;
             if( limit >0 &&
-                newSize > limit ) newSize=limit;
+                newSize > limit ) {
+                newSize=limit;
+            }
             tmp=new char[newSize];
         } else {
             newSize= buff.length * 2 + count ;
             if( limit > 0 &&
-                newSize > limit ) newSize=limit;
+                newSize > limit ) {
+                newSize=limit;
+            }
             tmp=new char[newSize];
         }
-        
+
         System.arraycopy(buff, 0, tmp, 0, end);
         buff = tmp;
         tmp = null;
     }
-    
+
     // -------------------- Conversion and getters --------------------
 
     @Override
@@ -494,7 +512,7 @@ public final class CharChunk implements 
         }
         return StringCache.toString(this);
     }
-    
+
     public String toStringInternal() {
         return new String(buff, start, end-start);
     }
@@ -504,7 +522,7 @@ public final class CharChunk implements 
         return Ascii.parseInt(buff, start,
                                 end-start);
     }
-    
+
     // -------------------- equals --------------------
 
     /**
@@ -553,8 +571,10 @@ public final class CharChunk implements 
 
     public boolean equals(char b2[], int off2, int len2) {
         char b1[]=buff;
-        if( b1==null && b2==null ) return true;
-        
+        if( b1==null && b2==null ) {
+            return true;
+        }
+
         if (b1== null || b2==null || end-start != len2) {
             return false;
         }
@@ -570,14 +590,16 @@ public final class CharChunk implements 
 
     public boolean equals(byte b2[], int off2, int len2) {
         char b1[]=buff;
-        if( b2==null && b1==null ) return true;
+        if( b2==null && b1==null ) {
+            return true;
+        }
 
         if (b1== null || b2==null || end-start != len2) {
             return false;
         }
         int off1 = start;
         int len=end-start;
-        
+
         while ( len-- > 0) {
             if ( b1[off1++] != (char)b2[off2++]) {
                 return false;
@@ -585,7 +607,7 @@ public final class CharChunk implements 
         }
         return true;
     }
-    
+
     /**
      * Returns true if the message bytes starts with the specified string.
      * @param s the string
@@ -604,7 +626,7 @@ public final class CharChunk implements 
         }
         return true;
     }
-    
+
     /**
      * Returns true if the message bytes starts with the specified string.
      * @param s the string
@@ -623,11 +645,11 @@ public final class CharChunk implements 
         }
         return true;
     }
-    
+
 
     // -------------------- Hash code  --------------------
 
-    // normal hash. 
+    // normal hash.
     public int hash() {
         int code=0;
         for (int i = start; i < start + end-start; i++) {
@@ -648,7 +670,7 @@ public final class CharChunk implements 
     public int indexOf(char c) {
         return indexOf( c, start);
     }
-    
+
     /**
      * Returns true if the message bytes starts with the specified string.
      * @param c the character
@@ -662,28 +684,35 @@ public final class CharChunk implements 
     {
         while( off < cend ) {
             char b=chars[off];
-            if( b==qq )
+            if( b==qq ) {
                 return off;
+            }
             off++;
         }
         return -1;
     }
-    
+
 
     public int indexOf( String src, int srcOff, int srcLen, int myOff ) {
         char first=src.charAt( srcOff );
 
-        // Look for first char 
+        // Look for first char
         int srcEnd = srcOff + srcLen;
-        
+
         for( int i=myOff+start; i <= (end - srcLen); i++ ) {
-            if( buff[i] != first ) continue;
+            if( buff[i] != first ) {
+                continue;
+            }
             // found first char, now look for a match
             int myPos=i+1;
             for( int srcPos=srcOff + 1; srcPos< srcEnd;) {
-                if( buff[myPos++] != src.charAt( srcPos++ ))
+                if( buff[myPos++] != src.charAt( srcPos++ )) {
                     break;
-                if( srcPos==srcEnd ) return i-start; // found it
+                }
+                if( srcPos==srcEnd )
+                 {
+                    return i-start; // found it
+                }
             }
         }
         return -1;
@@ -691,7 +720,9 @@ public final class CharChunk implements 
 
     // -------------------- utils
     private int min(int a, int b) {
-        if (a < b) return a;
+        if (a < b) {
+            return a;
+        }
         return b;
     }
 
@@ -719,5 +750,5 @@ public final class CharChunk implements 
     public int length() {
         return end - start;
     }
-    
+
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org