Class CharArrayBuffer
java.lang.Object
org.aspectj.org.eclipse.jdt.internal.core.util.CharArrayBuffer
The
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!
-
Field Summary
Modifier and TypeFieldDescriptionprotected char[][]
This is the buffer of char arrays which must be appended together during the getContents method.static int
The default buffer size.protected int
The end of the bufferprotected int[][]
A buffer of ranges which is maintained along with the buffer.protected int
The current size of the buffer. -
Constructor Summary
ConstructorDescriptionCreates aCharArrayBuffer
with the default buffer size (10).CharArrayBuffer(char[] first)
Creates aCharArrayBuffer
with the default buffer size, and sets the first element in the buffer to be the given char[].CharArrayBuffer(char[] first, int size)
Creates aCharArrayBuffer
with the given buffer size, and sets the first element in the buffer to be the given char array.CharArrayBuffer(int size)
Creates aCharArrayBuffer
with the given buffer size. -
Method Summary
Modifier and TypeMethodDescriptionappend(char c)
Appends the given char.append(char[] src)
Appends the entire given char array.append(char[] src, int start, int length)
Appends a sub array of the given array to the buffer.Appends the given String to the buffer.char[]
Returns the entire contents of the buffer as one char[] or null if nothing has been put in the buffer.toString()
Returns the contents of the buffer as a String, or an empty string if the buffer is empty.
-
Field Details
-
buffer
protected char[][] bufferThis is the buffer of char arrays which must be appended together during the getContents method. -
DEFAULT_BUFFER_SIZE
public static final int DEFAULT_BUFFER_SIZEThe default buffer size.- See Also:
- Constant Field Values
-
end
protected int endThe end of the buffer -
size
protected int sizeThe current size of the buffer. -
ranges
protected int[][] rangesA buffer of ranges which is maintained along with the buffer. Ranges are of the form {start, length}. Enables append(char[] array, int start, int end).
-
-
Constructor Details
-
CharArrayBuffer
public CharArrayBuffer()Creates aCharArrayBuffer
with the default buffer size (10). -
CharArrayBuffer
public CharArrayBuffer(char[] first)Creates aCharArrayBuffer
with the default buffer size, and sets the first element in the buffer to be the given char[].- Parameters:
first
- - the first element to be placed in the buffer, ignored if null
-
CharArrayBuffer
public CharArrayBuffer(char[] first, int size)Creates aCharArrayBuffer
with the given buffer size, and sets the first element in the buffer to be the given char array.- Parameters:
first
- - the first element of the buffer, ignored if null.size
- - the buffer size, if less than 1, set to the DEFAULT_BUFFER_SIZE.
-
CharArrayBuffer
public CharArrayBuffer(int size)Creates aCharArrayBuffer
with the given buffer size.- Parameters:
size
- - the size of the buffer.
-
-
Method Details
-
append
Appends the entire given char array. Given for convenience.- Parameters:
src
- - a char array which is appended to the end of the buffer.
-
append
Appends a sub array of the given array to the buffer.- Parameters:
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 appended- Throws:
ArrayIndexOutOfBoundsException
- - if arguments specify an array index out of bounds.
-
append
Appends the given char. Given for convenience.- Parameters:
c
- - a char which is appended to the end of the buffer.
-
append
Appends the given String to the buffer. Given for convenience, use #append(char[]) if possible- Parameters:
src
- - a char array which is appended to the end of the buffer.
-
getContents
public char[] getContents()Returns the entire contents of the buffer as one char[] or null if nothing has been put in the buffer. -
toString
Returns the contents of the buffer as a String, or an empty string if the buffer is empty.
-