<s> package org . eclipse . jdt . internal . core . util ; import org . eclipse . jdt . internal . compiler . util . Util ; public class CharArrayBuffer { protected char [ ] [ ] buffer ; public static final int DEFAULT_BUFFER_SIZE = 10 ; protected int end ; protected int size ; protected int [ ] [ ] ranges ; public CharArrayBuffer ( ) { this ( null , DEFAULT_BUFFER_SIZE ) ; } public CharArrayBuffer ( char [ ] first ) { this ( first , DEFAULT_BUFFER_SIZE ) ; } public CharArrayBuffer ( char [ ] first , int size ) { this . size = ( size > 0 ) ? size : DEFAULT_BUFFER_SIZE ; this . buffer = new char [ this . size ] [ ] ; this . ranges = new int [ this . size ] [ ] ; this . end = 0 ; if ( first != null ) append ( first , 0 , first . length ) ; } public CharArrayBuffer ( int size ) { this ( null , size ) ; } public CharArrayBuffer append ( char [ ] src ) { if ( src != null ) append ( src , 0 , src . length ) ; return this ; } public CharArrayBuffer append ( char [ ] src , int start , int length ) { if ( start < 0 ) throw new ArrayIndexOutOfBoundsException ( ) ; if ( length < 0 ) throw new ArrayIndexOutOfBoundsException ( ) ; if ( src != null ) { int srcLength = src . length ; if ( start > srcLength ) throw new ArrayIndexOutOfBoundsException ( ) ; if ( length + start > srcLength ) throw new ArrayIndexOutOfBoundsException ( ) ; if ( length > 0 ) { if ( this . end == this . size ) { int size2 = this . size * 2 ; System . arraycopy ( this . buffer , 0 , ( this . buffer = new char [ size2 ] [ ] ) , 0 , this . size ) ; System . arraycopy ( this . ranges , 0 , ( this . ranges = new int [ size2 ] [ ] ) , 0 , this . size ) ; this . size *= 2 ; } this . buffer [ this . end ] = src ; this . ranges [ this . end ] = new int [ ] { start , length } ; this . end ++ ; } } return this ; } public CharArrayBuffer append ( char c ) { append ( new char [ ] { c } , 0 , 1 ) ; return this ; } public CharArrayBuffer append ( String src ) { if ( src != null ) append ( src . toCharArray ( ) , 0 , src . length ( ) ) ; return this ; } public char [ ] getContents ( ) { if ( this . end == 0 ) return null ; int length = 0 ; for ( int i = 0 ; i < this . end ; i ++ ) length += this . ranges [ i ] [ 1 ] ; if ( length > 0 ) { char [ ] result = new char [ length ] ; int current = 0 ; for ( int i = 0 ; i < this . end ; i ++ ) { int [ ] range = this . ranges [ i ] ; int length2 = range [ 1 ] ; System . arraycopy ( this . buffer [ i ] , range [ 0 ] , result , current , length2 ) ; current += length2 ; } return result ; } return null ; } public String toString ( ) { char [ ] contents = getContents ( ) ; return ( contents != null ) ? new String ( contents ) : Util . EMPTY_STRING ; } } </s>