public class CharArrayBuffer
extends java.lang.Object
CharArrayBuffer is intended as a lightweight partial implementation
of the StringBuffer class, but using char[]'s instead of Strings.
The CharArrayBuffer maintains a list of char[]'s
which don't get appended until the user asks for them. The following
code illustrates how to use the class.
CharArrayBuffer buffer = new CharArrayBuffer(myCharArray);
buffer.append(moreBytes, 0, someLength);
myCharArray = buffer.getContents();
NOTE: This class is not Thread safe!
| Modifier and Type | Field and Description |
|---|---|
protected char[][] |
buffer
This is the buffer of char arrays which must be appended together
during the getContents method.
|
static int |
DEFAULT_BUFFER_SIZE
The default buffer size.
|
protected int |
end
The end of the buffer
|
protected int[][] |
ranges
A buffer of ranges which is maintained along with
the buffer.
|
protected int |
size
The current size of the buffer.
|
| Constructor and Description |
|---|
CharArrayBuffer()
Creates a
CharArrayBuffer with the default buffer size (10). |
CharArrayBuffer(char[] first)
Creates a
CharArrayBuffer with the default buffer size,
and sets the first element in the buffer to be the given char[]. |
CharArrayBuffer(char[] first,
int size)
Creates a
CharArrayBuffer with the given buffer size,
and sets the first element in the buffer to be the given char array. |
CharArrayBuffer(int size)
Creates a
CharArrayBuffer with the given buffer size. |
| Modifier and Type | Method and Description |
|---|---|
CharArrayBuffer |
append(char c)
Appends the given char.
|
CharArrayBuffer |
append(char[] src)
Appends the entire given char array.
|
CharArrayBuffer |
append(char[] src,
int start,
int length)
Appends a sub array of the given array to the buffer.
|
CharArrayBuffer |
append(java.lang.String src)
Appends the given String to the buffer.
|
char[] |
getContents()
Returns the entire contents of the buffer as one
char[] or null if nothing has been put in the buffer.
|
java.lang.String |
toString()
Returns the contents of the buffer as a String, or
an empty string if the buffer is empty.
|
protected char[][] buffer
public static final int DEFAULT_BUFFER_SIZE
protected int end
protected int size
protected int[][] ranges
public CharArrayBuffer()
CharArrayBuffer with the default buffer size (10).public CharArrayBuffer(char[] first)
CharArrayBuffer with the default buffer size,
and sets the first element in the buffer to be the given char[].first - - the first element to be placed in the buffer, ignored if nullpublic CharArrayBuffer(char[] first,
int size)
CharArrayBuffer with the given buffer size,
and sets the first element in the buffer to be the given char array.first - - the first element of the buffer, ignored if null.size - - the buffer size, if less than 1, set to the DEFAULT_BUFFER_SIZE.public CharArrayBuffer(int size)
CharArrayBuffer with the given buffer size.size - - the size of the buffer.public CharArrayBuffer append(char[] src)
src - - a char array which is appended to the end of the buffer.public CharArrayBuffer append(char[] src, int start, int length)
src - - the next array of characters to be appended to the buffer, ignored if nullstart - - the start index in the src array.length - - the number of characters from start to be appendedjava.lang.ArrayIndexOutOfBoundsException - - if arguments specify an array index out of bounds.public CharArrayBuffer append(char c)
c - - a char which is appended to the end of the buffer.public CharArrayBuffer append(java.lang.String src)
src - - a char array which is appended to the end of the buffer.public char[] getContents()
public java.lang.String toString()
toString in class java.lang.Object