Author: kkolinko
Date: Thu May 20 16:57:05 2010
New Revision: 946708

URL: http://svn.apache.org/viewvc?rev=946708&view=rev
Log:
CTR: Tabs to 8 spaces. No functional change.

Technically, it is a merge of r449335 from tc5.5.x,
and brings formatting in sync with tc5.5.x and trunk.
Some patches will be proposed for these classes soon.

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

Modified: tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/buf/ByteChunk.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/buf/ByteChunk.java?rev=946708&r1=946707&r2=946708&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/buf/ByteChunk.java 
(original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/buf/ByteChunk.java Thu May 
20 16:57:05 2010
@@ -91,8 +91,8 @@ 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. 
+        as most standards seem to converge, but the servlet API requires
+        8859_1, and this object is used mostly for servlets. 
     */
     public static final String DEFAULT_CHARACTER_ENCODING="ISO-8859-1";
         
@@ -122,48 +122,48 @@ public final class ByteChunk implements 
     }
 
     public ByteChunk( int initial ) {
-       allocate( initial, -1 );
+        allocate( initial, -1 );
     }
 
     //--------------------
     public ByteChunk getClone() {
-       try {
-           return (ByteChunk)this.clone();
-       } catch( Exception ex) {
-           return null;
-       }
+        try {
+            return (ByteChunk)this.clone();
+        } catch( Exception ex) {
+            return null;
+        }
     }
 
     public boolean isNull() {
-       return ! isSet; // buff==null;
+        return ! isSet; // buff==null;
     }
     
     /**
      * Resets the message buff to an uninitialized state.
      */
     public void recycle() {
-       //      buff = null;
-       enc=null;
-       start=0;
-       end=0;
-       isSet=false;
+        //        buff = null;
+        enc=null;
+        start=0;
+        end=0;
+        isSet=false;
     }
 
     public void reset() {
-       buff=null;
+        buff=null;
     }
 
     // -------------------- Setup --------------------
 
     public void allocate( int initial, int limit  ) {
-       isOutput=true;
-       if( buff==null || buff.length < initial ) {
-           buff=new byte[initial];
-       }    
-       this.limit=limit;
-       start=0;
-       end=0;
-       isSet=true;
+        isOutput=true;
+        if( buff==null || buff.length < initial ) {
+            buff=new byte[initial];
+        }    
+        this.limit=limit;
+        start=0;
+        end=0;
+        isSet=true;
     }
 
     /**
@@ -185,7 +185,7 @@ public final class ByteChunk implements 
     }
 
     public void setEncoding( String enc ) {
-       this.enc=enc;
+        this.enc=enc;
     }
     public String getEncoding() {
         if (enc == null)
@@ -197,14 +197,14 @@ public final class ByteChunk implements 
      * Returns the message bytes.
      */
     public byte[] getBytes() {
-       return getBuffer();
+        return getBuffer();
     }
 
     /**
      * Returns the message bytes.
      */
     public byte[] getBuffer() {
-       return buff;
+        return buff;
     }
 
     /**
@@ -212,16 +212,16 @@ public final class ByteChunk implements 
      * For output this is the end of the buffer.
      */
     public int getStart() {
-       return start;
+        return start;
     }
 
     public int getOffset() {
-       return start;
+        return start;
     }
 
     public void setOffset(int off) {
         if (end < off ) end=off;
-       start=off;
+        start=off;
     }
 
     /**
@@ -229,7 +229,7 @@ public final class ByteChunk implements 
      * XXX need to clean this up
      */
     public int getLength() {
-       return end-start;
+        return end-start;
     }
 
     /** Maximum amount of data in this buffer.
@@ -240,11 +240,11 @@ public final class ByteChunk implements 
      *  or throw exception.
      */
     public void setLimit(int limit) {
-       this.limit=limit;
+        this.limit=limit;
     }
     
     public int getLimit() {
-       return limit;
+        return limit;
     }
 
     /**
@@ -255,20 +255,20 @@ public final class ByteChunk implements 
     }
 
     /** When the buffer is full, write the data to the output channel.
-     *         Also used when large amount of data is appended.
+     *         Also used when large amount of data is appended.
      *
      *  If not set, the buffer will grow to the limit.
      */
     public void setByteOutputChannel(ByteOutputChannel out) {
-       this.out=out;
+        this.out=out;
     }
 
     public int getEnd() {
-       return end;
+        return end;
     }
 
     public void setEnd( int i ) {
-       end=i;
+        end=i;
     }
 
     // -------------------- Adding data to the buffer --------------------
@@ -278,44 +278,44 @@ public final class ByteChunk implements 
      * @throws IOException
      */
     public void append( char c )
-       throws IOException
+        throws IOException
     {
-       append( (byte)c);
+        append( (byte)c);
     }
 
     public void append( byte b )
-       throws IOException
+        throws IOException
     {
-       makeSpace( 1 );
+        makeSpace( 1 );
 
-       // couldn't make space
-       if( limit >0 && end >= limit ) {
-           flushBuffer();
-       }
-       buff[end++]=b;
+        // couldn't make space
+        if( limit >0 && end >= limit ) {
+            flushBuffer();
+        }
+        buff[end++]=b;
     }
 
     public void append( ByteChunk src )
-       throws IOException
+        throws IOException
     {
-       append( src.getBytes(), src.getStart(), src.getLength());
+        append( src.getBytes(), src.getStart(), src.getLength());
     }
 
     /** Add data to the buffer
      */
     public void append( byte src[], int off, int len )
-       throws IOException
+        throws IOException
     {
-       // will grow, up to limit
-       makeSpace( len );
+        // will grow, up to limit
+        makeSpace( len );
 
-       // if we don't have limit: makeSpace can grow as it wants
-       if( limit < 0 ) {
-           // assert: makeSpace made enough space
-           System.arraycopy( src, off, buff, end, len );
-           end+=len;
-           return;
-       }
+        // if we don't have limit: makeSpace can grow as it wants
+        if( limit < 0 ) {
+            // assert: makeSpace made enough space
+            System.arraycopy( src, off, buff, end, len );
+            end+=len;
+            return;
+        }
 
         // Optimize on a common case.
         // If the buffer is empty and the source is going to fill up all the
@@ -325,19 +325,19 @@ public final class ByteChunk implements 
             out.realWriteBytes( 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;
-       }
+        // 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;
+        }
 
-       // need more space than we can afford, need to flush
-       // buffer
+        // need more space than we can afford, need to flush
+        // buffer
 
-       // the buffer is already at ( or bigger than ) limit
+        // the buffer is already at ( or bigger than ) limit
 
         // We chunk the data into slices fitting in the buffer limit, although
         // if the data is written directly if it doesn't fit
@@ -424,61 +424,61 @@ public final class ByteChunk implements 
      * @throws IOException
      */
     public void flushBuffer()
-       throws IOException
+        throws IOException
     {
-       //assert out!=null
-       if( out==null ) {
-           throw new IOException( "Buffer overflow, no sink " + limit + " " +
-                                  buff.length  );
-       }
-       out.realWriteBytes( buff, start, end-start );
-       end=start;
+        //assert out!=null
+        if( out==null ) {
+            throw new IOException( "Buffer overflow, no sink " + limit + " " +
+                                   buff.length  );
+        }
+        out.realWriteBytes( buff, start, end-start );
+        end=start;
     }
 
     /** Make space for len chars. If len is small, allocate
-     * a reserve space too. Never grow bigger than limit.
+     *        a reserve space too. Never grow bigger than limit.
      */
     private void makeSpace(int count)
     {
-       byte[] tmp = null;
+        byte[] tmp = null;
 
-       int newSize;
-       int desiredSize=end + count;
+        int newSize;
+        int desiredSize=end + count;
+
+        // Can't grow above the limit
+        if( limit > 0 &&
+            desiredSize > limit) {
+            desiredSize=limit;
+        }
 
-       // Can't grow above the limit
-       if( limit > 0 &&
-           desiredSize > limit) {
-           desiredSize=limit;
-       }
-
-       if( buff==null ) {
-           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 ) {
-           return;
-       }
-       // grow in larger chunks
-       if( desiredSize < 2 * buff.length ) {
-           newSize= buff.length * 2;
-           if( limit >0 &&
-               newSize > limit ) newSize=limit;
-           tmp=new byte[newSize];
-       } else {
-           newSize= buff.length * 2 + count ;
-           if( limit > 0 &&
-               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;
+        if( buff==null ) {
+            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 ) {
+            return;
+        }
+        // grow in larger chunks
+        if( desiredSize < 2 * buff.length ) {
+            newSize= buff.length * 2;
+            if( limit >0 &&
+                newSize > limit ) newSize=limit;
+            tmp=new byte[newSize];
+        } else {
+            newSize= buff.length * 2 + count ;
+            if( limit > 0 &&
+                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 --------------------
@@ -519,7 +519,7 @@ public final class ByteChunk implements 
 
     public int getInt()
     {
-       return Ascii.parseInt(buff, start,end-start);
+        return Ascii.parseInt(buff, start,end-start);
     }
 
     public long getLong() {
@@ -535,21 +535,21 @@ public final class ByteChunk implements 
      * @return true if the comparison succeeded, false otherwise
      */
     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()) {
-           return false;
-       }
-       int boff = start;
-       for (int i = 0; i < blen; i++) {
-           if (b[boff++] != s.charAt(i)) {
-               return false;
-           }
-       }
-       return true;
+        // 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()) {
+            return false;
+        }
+        int boff = start;
+        for (int i = 0; i < blen; i++) {
+            if (b[boff++] != s.charAt(i)) {
+                return false;
+            }
+        }
+        return true;
     }
 
     /**
@@ -558,63 +558,63 @@ public final class ByteChunk implements 
      * @return true if the comparison succeeded, false otherwise
      */
     public boolean equalsIgnoreCase(String s) {
-       byte[] b = buff;
-       int blen = end-start;
-       if (b == null || blen != s.length()) {
-           return false;
-       }
-       int boff = start;
-       for (int i = 0; i < blen; i++) {
-           if (Ascii.toLower(b[boff++]) != Ascii.toLower(s.charAt(i))) {
-               return false;
-           }
-       }
-       return true;
+        byte[] b = buff;
+        int blen = end-start;
+        if (b == null || blen != s.length()) {
+            return false;
+        }
+        int boff = start;
+        for (int i = 0; i < blen; i++) {
+            if (Ascii.toLower(b[boff++]) != Ascii.toLower(s.charAt(i))) {
+                return false;
+            }
+        }
+        return true;
     }
 
     public boolean equals( ByteChunk bb ) {
-       return equals( bb.getBytes(), bb.getStart(), bb.getLength());
+        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;
+        byte b1[]=buff;
+        if( b1==null && b2==null ) return true;
 
-       int len=end-start;
-       if ( len2 != len || b1==null || b2==null ) 
-           return false;
-               
-       int off1 = start;
-
-       while ( len-- > 0) {
-           if (b1[off1++] != b2[off2++]) {
-               return false;
-           }
-       }
-       return true;
+        int len=end-start;
+        if ( len2 != len || b1==null || b2==null ) 
+            return false;
+                
+        int off1 = start;
+
+        while ( len-- > 0) {
+            if (b1[off1++] != b2[off2++]) {
+                return false;
+            }
+        }
+        return true;
     }
 
     public boolean equals( CharChunk cc ) {
-       return equals( cc.getChars(), cc.getStart(), cc.getLength());
+        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 (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;
-           }
-       }
-       return true;
+        // XXX works only for enc compatible with ASCII/UTF !!!
+        byte b1[]=buff;
+        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;
+            }
+        }
+        return true;
     }
 
     /**
@@ -622,19 +622,19 @@ public final class ByteChunk implements 
      * @param s the string
      */
     public boolean startsWith(String s) {
-       // Works only if enc==UTF
-       byte[] b = buff;
-       int blen = s.length();
-       if (b == null || blen > end-start) {
-           return false;
-       }
-       int boff = start;
-       for (int i = 0; i < blen; i++) {
-           if (b[boff++] != s.charAt(i)) {
-               return false;
-           }
-       }
-       return true;
+        // Works only if enc==UTF
+        byte[] b = buff;
+        int blen = s.length();
+        if (b == null || blen > end-start) {
+            return false;
+        }
+        int boff = start;
+        for (int i = 0; i < blen; i++) {
+            if (b[boff++] != s.charAt(i)) {
+                return false;
+            }
+        }
+        return true;
     }
 
     /* Returns true if the message bytes start with the specified byte array */
@@ -661,71 +661,71 @@ public final class ByteChunk implements 
      * @param pos The position
      */
     public boolean startsWithIgnoreCase(String s, int pos) {
-       byte[] b = buff;
-       int len = s.length();
-       if (b == null || len+pos > end-start) {
-           return false;
-       }
-       int off = start+pos;
-       for (int i = 0; i < len; i++) {
-           if (Ascii.toLower( b[off++] ) != Ascii.toLower( s.charAt(i))) {
-               return false;
-           }
-       }
-       return true;
+        byte[] b = buff;
+        int len = s.length();
+        if (b == null || len+pos > end-start) {
+            return false;
+        }
+        int off = start+pos;
+        for (int i = 0; i < len; i++) {
+            if (Ascii.toLower( b[off++] ) != Ascii.toLower( s.charAt(i))) {
+                return false;
+            }
+        }
+        return true;
     }
 
     public int indexOf( String src, int srcOff, int srcLen, int myOff ) {
-       char first=src.charAt( srcOff );
+        char first=src.charAt( srcOff );
 
-       // Look for first char 
-       int srcEnd = srcOff + srcLen;
+        // Look for first char 
+        int srcEnd = srcOff + srcLen;
         
-       for( int i=myOff+start; i <= (end - srcLen); i++ ) {
-           if( buff[i] != first ) continue;
-           // found first char, now look for a match
+        for( int i=myOff+start; i <= (end - srcLen); i++ ) {
+            if( buff[i] != first ) continue;
+            // found first char, now look for a match
             int myPos=i+1;
-           for( int srcPos=srcOff + 1; srcPos< srcEnd; ) {
+            for( int srcPos=srcOff + 1; srcPos< srcEnd; ) {
                 if( buff[myPos++] != src.charAt( srcPos++ ))
-                   break;
+                    break;
                 if( srcPos==srcEnd ) return i-start; // found it
-           }
-       }
-       return -1;
+            }
+        }
+        return -1;
     }
 
     // -------------------- Hash code  --------------------
 
     // normal hash. 
     public int hash() {
-       return hashBytes( buff, start, end-start);
+        return hashBytes( buff, start, end-start);
     }
 
     // hash ignoring case
     public int hashIgnoreCase() {
-       return hashBytesIC( buff, start, end-start );
+        return hashBytesIC( buff, start, end-start );
     }
 
     private static int hashBytes( byte buff[], int start, int bytesLen ) {
-       int max=start+bytesLen;
-       byte bb[]=buff;
-       int code=0;
-       for (int i = start; i < max ; i++) {
-           code = code * 37 + bb[i];
-       }
-       return code;
+        int max=start+bytesLen;
+        byte bb[]=buff;
+        int code=0;
+        for (int i = start; i < max ; i++) {
+            code = code * 37 + bb[i];
+        }
+        return code;
     }
 
     private static int hashBytesIC( byte bytes[], int start,
-                                   int bytesLen )
+                                    int bytesLen )
     {
-       int max=start+bytesLen;
-       byte bb[]=bytes;
-       int code=0;
-       for (int i = start; i < max ; i++) {
-           code = code * 37 + Ascii.toLower(bb[i]);
-       }
-       return code;
+        int max=start+bytesLen;
+        byte bb[]=bytes;
+        int code=0;
+        for (int i = start; i < max ; i++) {
+            code = code * 37 + Ascii.toLower(bb[i]);
+        }
+        return code;
     }
 
     /**
@@ -734,51 +734,51 @@ public final class ByteChunk implements 
      * @param starting The start position
      */
     public int indexOf(char c, int starting) {
-       int ret = indexOf( buff, start+starting, end, c);
-       return (ret >= start) ? ret - start : -1;
+        int ret = indexOf( buff, start+starting, end, c);
+        return (ret >= start) ? ret - start : -1;
     }
 
     public static int  indexOf( byte bytes[], int off, int end, char qq )
     {
-       // Works only for UTF 
-       while( off < end ) {
-           byte b=bytes[off];
-           if( b==qq )
-               return off;
-           off++;
-       }
-       return -1;
+        // Works only for UTF 
+        while( off < end ) {
+            byte b=bytes[off];
+            if( b==qq )
+                return off;
+            off++;
+        }
+        return -1;
     }
 
     /** Find a character, no side effects.
      *  @return index of char if found, -1 if not
      */
     public static int findChar( byte buf[], int start, int end, char c ) {
-       byte b=(byte)c;
-       int offset = start;
-       while (offset < end) {
-           if (buf[offset] == b) {
-               return offset;
-           }
-           offset++;
-       }
-       return -1;
+        byte b=(byte)c;
+        int offset = start;
+        while (offset < end) {
+            if (buf[offset] == b) {
+                return offset;
+            }
+            offset++;
+        }
+        return -1;
     }
 
     /** Find a character, no side effects.
      *  @return index of char if found, -1 if not
      */
     public static int findChars( byte buf[], int start, int end, byte c[] ) {
-       int clen=c.length;
-       int offset = start;
-       while (offset < end) {
-           for( int i=0; i<clen; i++ ) 
-               if (buf[offset] == c[i]) {
-                   return offset;
-               }
-           offset++;
-       }
-       return -1;
+        int clen=c.length;
+        int offset = start;
+        while (offset < end) {
+            for( int i=0; i<clen; i++ ) 
+                if (buf[offset] == c[i]) {
+                    return offset;
+                }
+            offset++;
+        }
+        return -1;
     }
 
     /** Find the first character != c 
@@ -786,29 +786,30 @@ public final class ByteChunk implements 
      */
     public static int findNotChars( byte buf[], int start, int end, byte c[] )
     {
-       int clen=c.length;
-       int offset = start;
-       boolean found;
-               
-       while (offset < end) {
-           found=true;
-           for( int i=0; i<clen; i++ ) {
-               if (buf[offset] == c[i]) {
-                   found=false;
-                   break;
-               }
-           }
-           if( found ) { // buf[offset] != c[0..len]
-               return offset;
-           }
-           offset++;
-       }
-       return -1;
+        int clen=c.length;
+        int offset = start;
+        boolean found;
+                
+        while (offset < end) {
+            found=true;
+            for( int i=0; i<clen; i++ ) {
+                if (buf[offset] == c[i]) {
+                    found=false;
+                    break;
+                }
+            }
+            if( found ) { // buf[offset] != c[0..len]
+                return offset;
+            }
+            offset++;
+        }
+        return -1;
     }
 
 
     /**
-     * Convert specified String to a byte array. This ONLY WORKS for ascii, 
UTF chars will be truncated.
+     * 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/tc6.0.x/trunk/java/org/apache/tomcat/util/buf/CharChunk.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/buf/CharChunk.java?rev=946708&r1=946707&r2=946708&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/buf/CharChunk.java 
(original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/buf/CharChunk.java Thu May 
20 16:57:05 2010
@@ -48,9 +48,9 @@ public final class CharChunk implements 
      *  grow the buffer ( up to the limit ) or send it to a channel.
      */
     public static interface CharOutputChannel {
-       /** Send the bytes ( usually the internal conversion buffer ).
-        *  Expect 8k output if the buffer is full.
-        */
+        /** Send the bytes ( usually the internal conversion buffer ).
+         *  Expect 8k output if the buffer is full.
+         */
         public void realWriteChars(char cbuf[], int off, int len)
             throws IOException;
     }
@@ -82,50 +82,50 @@ public final class CharChunk implements 
     }
 
     public CharChunk(int size) {
-       allocate( size, -1 );
+        allocate( size, -1 );
     }
 
     // --------------------
     
     public CharChunk getClone() {
-       try {
-           return (CharChunk)this.clone();
-       } catch( Exception ex) {
-           return null;
-       }
+        try {
+            return (CharChunk)this.clone();
+        } catch( Exception ex) {
+            return null;
+        }
     }
 
     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.
      */
     public void recycle() {
-       //      buff=null;
-       isSet=false; // XXX
-       start=0;
-       end=0;
+        //        buff=null;
+        isSet=false; // XXX
+        start=0;
+        end=0;
     }
 
     public void reset() {
-       buff=null;
+        buff=null;
     }
 
     // -------------------- Setup --------------------
 
     public void allocate( int initial, int limit  ) {
-       isOutput=true;
-       if( buff==null || buff.length < initial ) {
-           buff=new char[initial];
-       }
-       this.limit=limit;
-       start=0;
-       end=0;
-       isOutput=true;
-       isSet=true;
+        isOutput=true;
+        if( buff==null || buff.length < initial ) {
+            buff=new char[initial];
+        }
+        this.limit=limit;
+        start=0;
+        end=0;
+        isOutput=true;
+        isSet=true;
     }
 
 
@@ -148,11 +148,11 @@ public final class CharChunk implements 
      *  or throw exception.
      */
     public void setLimit(int limit) {
-       this.limit=limit;
+        this.limit=limit;
     }
     
     public int getLimit() {
-       return limit;
+        return limit;
     }
 
     /**
@@ -163,23 +163,23 @@ public final class CharChunk implements 
     }
 
     /** When the buffer is full, write the data to the output channel.
-     *         Also used when large amount of data is appended.
+     *         Also used when large amount of data is appended.
      *
      *  If not set, the buffer will grow to the limit.
      */
     public void setCharOutputChannel(CharOutputChannel out) {
-       this.out=out;
+        this.out=out;
     }
 
     // compat 
     public char[] getChars()
     {
-       return getBuffer();
+        return getBuffer();
     }
     
     public char[] getBuffer()
     {
-       return buff;
+        return buff;
     }
     
     /**
@@ -187,71 +187,71 @@ public final class CharChunk implements 
      * For output this is the end of the buffer.
      */
     public int getStart() {
-       return start;
+        return start;
     }
     
     public int getOffset() {
-       return start;
+        return start;
     }
 
     /**
      * Returns the start offset of the bytes.
      */
     public void setOffset(int off) {
-       start=off;
+        start=off;
     }
 
     /**
      * Returns the length of the bytes.
      */
     public int getLength() {
-       return end-start;
+        return end-start;
     }
 
 
     public int getEnd() {
-       return end;
+        return end;
     }
 
     public void setEnd( int i ) {
-       end=i;
+        end=i;
     }
 
     // -------------------- Adding data --------------------
     
     public void append( char b )
-       throws IOException
+        throws IOException
     {
-       makeSpace( 1 );
+        makeSpace( 1 );
 
-       // couldn't make space
-       if( limit >0 && end >= limit ) {
-           flushBuffer();
-       }
-       buff[end++]=b;
+        // couldn't make space
+        if( limit >0 && end >= limit ) {
+            flushBuffer();
+        }
+        buff[end++]=b;
     }
     
     public void append( CharChunk src )
-       throws IOException
+        throws IOException
     {
-       append( src.getBuffer(), src.getOffset(), src.getLength());
+        append( src.getBuffer(), src.getOffset(), src.getLength());
     }
 
     /** Add data to the buffer
      */
     public void append( char src[], int off, int len )
-       throws IOException
+        throws IOException
     {
-       // will grow, up to limit
-       makeSpace( len );
+        // will grow, up to limit
+        makeSpace( len );
 
-       // if we don't have limit: makeSpace can grow as it wants
-       if( limit < 0 ) {
-           // assert: makeSpace made enough space
-           System.arraycopy( src, off, buff, end, len );
-           end+=len;
-           return;
-       }
+        // if we don't have limit: makeSpace can grow as it wants
+        if( limit < 0 ) {
+            // assert: makeSpace made enough space
+            System.arraycopy( src, off, buff, end, len );
+            end+=len;
+            return;
+        }
 
         // Optimize on a common case.
         // If the source is going to fill up all the space in buffer, may
@@ -260,82 +260,82 @@ 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 );
+        
+        // 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;
-       }
-
-       // need more space than we can afford, need to flush
-       // 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
-       // copy the first part, flush, then copy the second part - 1 write
-       // and still have some space for more. We'll still have 2 writes, but
-       // we write more on the first.
-
-       if( len + end < 2 * limit ) {
-           /* If the request length exceeds the size of the output buffer,
-              flush the output buffer and then write the data directly.
-              We can't avoid 2 writes, but we can write more on the second
-           */
-           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 );
-       }
+            end+=len;
+            return;
+        }
+
+        // need more space than we can afford, need to flush
+        // 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
+        // copy the first part, flush, then copy the second part - 1 write
+        // and still have some space for more. We'll still have 2 writes, but
+        // we write more on the first.
+
+        if( len + end < 2 * limit ) {
+            /* If the request length exceeds the size of the output buffer,
+               flush the output buffer and then write the data directly.
+               We can't avoid 2 writes, but we can write more on the second
+            */
+            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 );
+        }
     }
 
 
     /** Add data to the buffer
      */
     public void append( StringBuffer sb )
-       throws IOException
+        throws IOException
     {
-       int len=sb.length();
+        int len=sb.length();
+
+        // will grow, up to limit
+        makeSpace( len );
 
-       // will grow, up to limit
-       makeSpace( len );
+        // if we don't have limit: makeSpace can grow as it wants
+        if( limit < 0 ) {
+            // assert: makeSpace made enough space
+            sb.getChars(0, len, buff, end );
+            end+=len;
+            return;
+        }
 
-       // if we don't have limit: makeSpace can grow as it wants
-       if( limit < 0 ) {
-           // assert: makeSpace made enough space
-           sb.getChars(0, len, buff, end );
-           end+=len;
-           return;
-       }
-
-       int off=0;
-       int sbOff = off;
-       int sbEnd = off + len;
-       while (sbOff < sbEnd) {
-           int d = min(limit - end, sbEnd - sbOff);
-           sb.getChars( sbOff, sbOff+d, buff, end);
-           sbOff += d;
-           end += d;
-           if (end >= limit)
-               flushBuffer();
-       }
+        int off=0;
+        int sbOff = off;
+        int sbEnd = off + len;
+        while (sbOff < sbEnd) {
+            int d = min(limit - end, sbEnd - sbOff);
+            sb.getChars( sbOff, sbOff+d, buff, end);
+            sbOff += d;
+            end += d;
+            if (end >= limit)
+                flushBuffer();
+        }
     }
 
     /** Append a string to the buffer
@@ -347,29 +347,29 @@ public final class CharChunk implements 
     /** Append a string to the buffer
      */
     public void append(String s, int off, int len) throws IOException {
-       if (s==null) return;
-       
-       // will grow, up to limit
-       makeSpace( len );
-
-       // if we don't have limit: makeSpace can grow as it wants
-       if( limit < 0 ) {
-           // assert: makeSpace made enough space
-           s.getChars(off, off+len, buff, end );
-           end+=len;
-           return;
-       }
-
-       int sOff = off;
-       int sEnd = off + len;
-       while (sOff < sEnd) {
-           int d = min(limit - end, sEnd - sOff);
-           s.getChars( sOff, sOff+d, buff, end);
-           sOff += d;
-           end += d;
-           if (end >= limit)
-               flushBuffer();
-       }
+        if (s==null) return;
+        
+        // will grow, up to limit
+        makeSpace( len );
+
+        // if we don't have limit: makeSpace can grow as it wants
+        if( limit < 0 ) {
+            // assert: makeSpace made enough space
+            s.getChars(off, off+len, buff, end );
+            end+=len;
+            return;
+        }
+
+        int sOff = off;
+        int sEnd = off + len;
+        while (sOff < sEnd) {
+            int d = min(limit - end, sEnd - sOff);
+            s.getChars( sOff, sOff+d, buff, end);
+            sOff += d;
+            end += d;
+            if (end >= limit)
+                flushBuffer();
+        }
     }
     
     // -------------------- Removing data from the buffer --------------------
@@ -430,59 +430,59 @@ public final class CharChunk implements 
 
 
     public void flushBuffer()
-       throws IOException
+        throws IOException
     {
-       //assert out!=null
-       if( out==null ) {
-           throw new IOException( "Buffer overflow, no sink " + limit + " " +
-                                  buff.length  );
-       }
-       out.realWriteChars( buff, start, end - start );
-       end=start;
+        //assert out!=null
+        if( out==null ) {
+            throw new IOException( "Buffer overflow, no sink " + limit + " " +
+                                   buff.length  );
+        }
+        out.realWriteChars( buff, start, end - start );
+        end=start;
     }
 
     /** Make space for len chars. If len is small, allocate
-     * a reserve space too. Never grow bigger than limit.
+     *        a reserve space too. Never grow bigger than limit.
      */
     private void makeSpace(int count)
     {
-       char[] tmp = null;
+        char[] tmp = null;
+
+        int newSize;
+        int desiredSize=end + count;
 
-       int newSize;
-       int desiredSize=end + count;
+        // Can't grow above the limit
+        if( limit > 0 &&
+            desiredSize > limit) {
+            desiredSize=limit;
+        }
+
+        if( buff==null ) {
+            if( desiredSize < 256 ) desiredSize=256; // take a minimum
+            buff=new char[desiredSize];
+        }
 
-       // Can't grow above the limit
-       if( limit > 0 &&
-           desiredSize > limit) {
-           desiredSize=limit;
-       }
-
-       if( buff==null ) {
-           if( desiredSize < 256 ) desiredSize=256; // take a minimum
-           buff=new char[desiredSize];
-       }
-
-       // limit < buf.length ( the buffer is already big )
-       // or we already have space XXX
-       if( desiredSize <= buff.length) {
-           return;
-       }
-       // grow in larger chunks
-       if( desiredSize < 2 * buff.length ) {
-           newSize= buff.length * 2;
-           if( limit >0 &&
-               newSize > limit ) newSize=limit;
-           tmp=new char[newSize];
-       } else {
-           newSize= buff.length * 2 + count ;
-           if( limit > 0 &&
-               newSize > limit ) newSize=limit;
-           tmp=new char[newSize];
-       }
-       
-       System.arraycopy(buff, 0, tmp, 0, end);
-       buff = tmp;
-       tmp = null;
+        // limit < buf.length ( the buffer is already big )
+        // or we already have space XXX
+        if( desiredSize <= buff.length) {
+            return;
+        }
+        // grow in larger chunks
+        if( desiredSize < 2 * buff.length ) {
+            newSize= buff.length * 2;
+            if( limit >0 &&
+                newSize > limit ) newSize=limit;
+            tmp=new char[newSize];
+        } else {
+            newSize= buff.length * 2 + count ;
+            if( limit > 0 &&
+                newSize > limit ) newSize=limit;
+            tmp=new char[newSize];
+        }
+        
+        System.arraycopy(buff, 0, tmp, 0, end);
+        buff = tmp;
+        tmp = null;
     }
     
     // -------------------- Conversion and getters --------------------
@@ -502,8 +502,8 @@ public final class CharChunk implements 
 
     public int getInt()
     {
-       return Ascii.parseInt(buff, start,
-                               end-start);
+        return Ascii.parseInt(buff, start,
+                                end-start);
     }
     
     // -------------------- equals --------------------
@@ -514,18 +514,18 @@ public final class CharChunk implements 
      * @return true if the comparison succeeded, false otherwise
      */
     public boolean equals(String s) {
-       char[] c = buff;
-       int len = end-start;
-       if (c == null || len != s.length()) {
-           return false;
-       }
-       int off = start;
-       for (int i = 0; i < len; i++) {
-           if (c[off++] != s.charAt(i)) {
-               return false;
-           }
-       }
-       return true;
+        char[] c = buff;
+        int len = end-start;
+        if (c == null || len != s.length()) {
+            return false;
+        }
+        int off = start;
+        for (int i = 0; i < len; i++) {
+            if (c[off++] != s.charAt(i)) {
+                return false;
+            }
+        }
+        return true;
     }
 
     /**
@@ -534,57 +534,57 @@ public final class CharChunk implements 
      * @return true if the comparison succeeded, false otherwise
      */
     public boolean equalsIgnoreCase(String s) {
-       char[] c = buff;
-       int len = end-start;
-       if (c == null || len != s.length()) {
-           return false;
-       }
-       int off = start;
-       for (int i = 0; i < len; i++) {
-           if (Ascii.toLower( c[off++] ) != Ascii.toLower( s.charAt(i))) {
-               return false;
-           }
-       }
-       return true;
+        char[] c = buff;
+        int len = end-start;
+        if (c == null || len != s.length()) {
+            return false;
+        }
+        int off = start;
+        for (int i = 0; i < len; i++) {
+            if (Ascii.toLower( c[off++] ) != Ascii.toLower( s.charAt(i))) {
+                return false;
+            }
+        }
+        return true;
     }
 
     public boolean equals(CharChunk cc) {
-       return equals( cc.getChars(), cc.getOffset(), cc.getLength());
+        return equals( cc.getChars(), cc.getOffset(), cc.getLength());
     }
 
     public boolean equals(char b2[], int off2, int len2) {
-       char b1[]=buff;
-       if( b1==null && b2==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++] != b2[off2++]) {
-               return false;
-           }
-       }
-       return true;
+        char b1[]=buff;
+        if( b1==null && b2==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++] != b2[off2++]) {
+                return false;
+            }
+        }
+        return true;
     }
 
     public boolean equals(byte b2[], int off2, int len2) {
-       char b1[]=buff;
-       if( b2==null && b1==null ) return true;
+        char b1[]=buff;
+        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;
-           }
-       }
-       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;
+            }
+        }
+        return true;
     }
     
     /**
@@ -592,18 +592,18 @@ public final class CharChunk implements 
      * @param s the string
      */
     public boolean startsWith(String s) {
-       char[] c = buff;
-       int len = s.length();
-       if (c == null || len > end-start) {
-           return false;
-       }
-       int off = start;
-       for (int i = 0; i < len; i++) {
-           if (c[off++] != s.charAt(i)) {
-               return false;
-           }
-       }
-       return true;
+        char[] c = buff;
+        int len = s.length();
+        if (c == null || len > end-start) {
+            return false;
+        }
+        int off = start;
+        for (int i = 0; i < len; i++) {
+            if (c[off++] != s.charAt(i)) {
+                return false;
+            }
+        }
+        return true;
     }
     
     /**
@@ -611,18 +611,18 @@ public final class CharChunk implements 
      * @param s the string
      */
     public boolean startsWithIgnoreCase(String s, int pos) {
-       char[] c = buff;
-       int len = s.length();
-       if (c == null || len+pos > end-start) {
-           return false;
-       }
-       int off = start+pos;
-       for (int i = 0; i < len; i++) {
-           if (Ascii.toLower( c[off++] ) != Ascii.toLower( s.charAt(i))) {
-               return false;
-           }
-       }
-       return true;
+        char[] c = buff;
+        int len = s.length();
+        if (c == null || len+pos > end-start) {
+            return false;
+        }
+        int off = start+pos;
+        for (int i = 0; i < len; i++) {
+            if (Ascii.toLower( c[off++] ) != Ascii.toLower( s.charAt(i))) {
+                return false;
+            }
+        }
+        return true;
     }
     
 
@@ -630,24 +630,24 @@ public final class CharChunk implements 
 
     // normal hash. 
     public int hash() {
-       int code=0;
-       for (int i = start; i < start + end-start; i++) {
-           code = code * 37 + buff[i];
-       }
-       return code;
+        int code=0;
+        for (int i = start; i < start + end-start; i++) {
+            code = code * 37 + buff[i];
+        }
+        return code;
     }
 
     // hash ignoring case
     public int hashIgnoreCase() {
-       int code=0;
-       for (int i = start; i < end; i++) {
-           code = code * 37 + Ascii.toLower(buff[i]);
-       }
-       return code;
+        int code=0;
+        for (int i = start; i < end; i++) {
+            code = code * 37 + Ascii.toLower(buff[i]);
+        }
+        return code;
     }
 
     public int indexOf(char c) {
-       return indexOf( c, start);
+        return indexOf( c, start);
     }
     
     /**
@@ -655,45 +655,45 @@ public final class CharChunk implements 
      * @param c the character
      */
     public int indexOf(char c, int starting) {
-       int ret = indexOf( buff, start+starting, end, c );
-       return (ret >= start) ? ret - start : -1;
+        int ret = indexOf( buff, start+starting, end, c );
+        return (ret >= start) ? ret - start : -1;
     }
 
     public static int indexOf( char chars[], int off, int cend, char qq )
     {
-       while( off < cend ) {
-           char b=chars[off];
-           if( b==qq )
-               return off;
-           off++;
-       }
-       return -1;
+        while( off < cend ) {
+            char b=chars[off];
+            if( b==qq )
+                return off;
+            off++;
+        }
+        return -1;
     }
     
 
     public int indexOf( String src, int srcOff, int srcLen, int myOff ) {
-       char first=src.charAt( srcOff );
+        char first=src.charAt( srcOff );
 
-       // Look for first char 
-       int srcEnd = srcOff + srcLen;
+        // Look for first char 
+        int srcEnd = srcOff + srcLen;
         
-       for( int i=myOff+start; i <= (end - srcLen); i++ ) {
-           if( buff[i] != first ) continue;
-           // found first char, now look for a match
+        for( int i=myOff+start; i <= (end - srcLen); i++ ) {
+            if( buff[i] != first ) continue;
+            // found first char, now look for a match
             int myPos=i+1;
-           for( int srcPos=srcOff + 1; srcPos< srcEnd; ) {
+            for( int srcPos=srcOff + 1; srcPos< srcEnd; ) {
                 if( buff[myPos++] != src.charAt( srcPos++ ))
-                   break;
+                    break;
                 if( srcPos==srcEnd ) return i-start; // found it
-           }
-       }
-       return -1;
+            }
+        }
+        return -1;
     }
 
     // -------------------- utils
     private int min(int a, int b) {
-       if (a < b) return a;
-       return b;
+        if (a < b) return a;
+        return b;
     }
 
     // Char sequence impl



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

Reply via email to