Package org.apache.http.util
Class CharArrayBuffer
java.lang.Object
org.apache.http.util.CharArrayBuffer
- All Implemented Interfaces:
Serializable,CharSequence
A resizable char array.
- Since:
- 4.0
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCharArrayBuffer(int capacity) Creates an instance ofCharArrayBufferwith the given initial capacity. -
Method Summary
Modifier and TypeMethodDescriptionvoidappend(byte[] b, int off, int len) Appendslenbytes to this buffer from the given source array starting at indexoff.voidappend(char ch) Appendschchar to this buffer.voidappend(char[] b, int off, int len) Appendslenchars to this buffer from the given source array starting at indexoff.voidAppends chars of the textual representation of the given object to this buffer.voidAppends chars of the given string to this buffer.voidappend(ByteArrayBuffer b, int off, int len) Appendslenbytes to this buffer from the given source array starting at indexoff.voidAppends all chars to this buffer from the given source buffer starting at index0.voidappend(CharArrayBuffer b, int off, int len) Appendslenchars to this buffer from the given source buffer starting at indexoff.char[]buffer()Returns reference to the underlying char array.intcapacity()Returns the current capacity.charcharAt(int i) Returns thecharvalue in this buffer at the specified index.voidclear()Clears content of the buffer.voidensureCapacity(int required) Ensures that the capacity is at least equal to the specified minimum.intindexOf(int ch) Returns the index within this buffer of the first occurrence of the specified character, starting the search at0and finishing atlength().intindexOf(int ch, int from, int to) Returns the index within this buffer of the first occurrence of the specified character, starting the search at the specifiedbeginIndexand finishing atendIndex.booleanisEmpty()booleanisFull()intlength()Returns the length of the buffer (char count).voidsetLength(int len) Sets the length of the buffer.subSequence(int beginIndex, int endIndex) substring(int beginIndex, int endIndex) Returns a substring of this buffer.substringTrimmed(int beginIndex, int endIndex) Returns a substring of this buffer with leading and trailing whitespace omitted.char[]Converts the content of this buffer to an array of chars.toString()Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.CharSequence
chars, codePoints
-
Constructor Details
-
CharArrayBuffer
public CharArrayBuffer(int capacity) Creates an instance ofCharArrayBufferwith the given initial capacity.- Parameters:
capacity- the capacity
-
-
Method Details
-
append
public void append(char[] b, int off, int len) Appendslenchars to this buffer from the given source array starting at indexoff. The capacity of the buffer is increased, if necessary, to accommodate alllenchars.- Parameters:
b- the chars to be appended.off- the index of the first char to append.len- the number of chars to append.- Throws:
IndexOutOfBoundsException- ifoffis out of range,lenis negative, oroff+lenis out of range.
-
append
Appends chars of the given string to this buffer. The capacity of the buffer is increased, if necessary, to accommodate all chars.- Parameters:
str- the string.
-
append
Appendslenchars to this buffer from the given source buffer starting at indexoff. The capacity of the destination buffer is increased, if necessary, to accommodate alllenchars.- Parameters:
b- the source buffer to be appended.off- the index of the first char to append.len- the number of chars to append.- Throws:
IndexOutOfBoundsException- ifoffis out of range,lenis negative, oroff+lenis out of range.
-
append
Appends all chars to this buffer from the given source buffer starting at index0. The capacity of the destination buffer is increased, if necessary, to accommodate alllength()chars.- Parameters:
b- the source buffer to be appended.
-
append
public void append(char ch) Appendschchar to this buffer. The capacity of the buffer is increased, if necessary, to accommodate the additional char.- Parameters:
ch- the char to be appended.
-
append
public void append(byte[] b, int off, int len) Appendslenbytes to this buffer from the given source array starting at indexoff. The capacity of the buffer is increased, if necessary, to accommodate alllenbytes.The bytes are converted to chars using simple cast.
- Parameters:
b- the bytes to be appended.off- the index of the first byte to append.len- the number of bytes to append.- Throws:
IndexOutOfBoundsException- ifoffis out of range,lenis negative, oroff+lenis out of range.
-
append
Appendslenbytes to this buffer from the given source array starting at indexoff. The capacity of the buffer is increased, if necessary, to accommodate alllenbytes.The bytes are converted to chars using simple cast.
- Parameters:
b- the bytes to be appended.off- the index of the first byte to append.len- the number of bytes to append.- Throws:
IndexOutOfBoundsException- ifoffis out of range,lenis negative, oroff+lenis out of range.
-
append
Appends chars of the textual representation of the given object to this buffer. The capacity of the buffer is increased, if necessary, to accommodate all chars.- Parameters:
obj- the object.
-
clear
public void clear()Clears content of the buffer. The underlying char array is not resized. -
toCharArray
public char[] toCharArray()Converts the content of this buffer to an array of chars.- Returns:
- char array
-
charAt
public char charAt(int i) Returns thecharvalue in this buffer at the specified index. The index argument must be greater than or equal to0, and less than the length of this buffer.- Specified by:
charAtin interfaceCharSequence- Parameters:
i- the index of the desired char value.- Returns:
- the char value at the specified index.
- Throws:
IndexOutOfBoundsException- ifindexis negative or greater than or equal tolength().
-
buffer
public char[] buffer()Returns reference to the underlying char array.- Returns:
- the char array.
-
capacity
public int capacity()Returns the current capacity. The capacity is the amount of storage available for newly appended chars, beyond which an allocation will occur.- Returns:
- the current capacity
-
length
public int length()Returns the length of the buffer (char count).- Specified by:
lengthin interfaceCharSequence- Returns:
- the length of the buffer
-
ensureCapacity
public void ensureCapacity(int required) Ensures that the capacity is at least equal to the specified minimum. If the current capacity is less than the argument, then a new internal array is allocated with greater capacity. If therequiredargument is non-positive, this method takes no action.- Parameters:
required- the minimum required capacity.
-
setLength
public void setLength(int len) Sets the length of the buffer. The new length value is expected to be less than the current capacity and greater than or equal to0.- Parameters:
len- the new length- Throws:
IndexOutOfBoundsException- if thelenargument is greater than the current capacity of the buffer or less than0.
-
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfaceCharSequence- Returns:
trueif this buffer is empty,falseotherwise.
-
isFull
public boolean isFull()- Returns:
trueif this buffer is full,falseotherwise.
-
indexOf
public int indexOf(int ch, int from, int to) Returns the index within this buffer of the first occurrence of the specified character, starting the search at the specifiedbeginIndexand finishing atendIndex. If no such character occurs in this buffer within the specified bounds,-1is returned.There is no restriction on the value of
beginIndexandendIndex. IfbeginIndexis negative, it has the same effect as if it were zero. IfendIndexis greater thanlength(), it has the same effect as if it werelength(). If thebeginIndexis greater than theendIndex,-1is returned.- Parameters:
ch- the char to search for.from- the index to start the search from.to- the index to finish the search at.- Returns:
- the index of the first occurrence of the character in the buffer
within the given bounds, or
-1if the character does not occur.
-
indexOf
public int indexOf(int ch) Returns the index within this buffer of the first occurrence of the specified character, starting the search at0and finishing atlength(). If no such character occurs in this buffer within those bounds,-1is returned.- Parameters:
ch- the char to search for.- Returns:
- the index of the first occurrence of the character in the
buffer, or
-1if the character does not occur.
-
substring
Returns a substring of this buffer. The substring begins at the specifiedbeginIndexand extends to the character at indexendIndex - 1.- Parameters:
beginIndex- the beginning index, inclusive.endIndex- the ending index, exclusive.- Returns:
- the specified substring.
- Throws:
StringIndexOutOfBoundsException- if thebeginIndexis negative, orendIndexis larger than the length of this buffer, orbeginIndexis larger thanendIndex.
-
substringTrimmed
Returns a substring of this buffer with leading and trailing whitespace omitted. The substring begins with the first non-whitespace character frombeginIndexand extends to the last non-whitespace character with the index lesser thanendIndex.- Parameters:
beginIndex- the beginning index, inclusive.endIndex- the ending index, exclusive.- Returns:
- the specified substring.
- Throws:
IndexOutOfBoundsException- if thebeginIndexis negative, orendIndexis larger than the length of this buffer, orbeginIndexis larger thanendIndex.
-
subSequence
- Specified by:
subSequencein interfaceCharSequence- Since:
- 4.4
-
toString
- Specified by:
toStringin interfaceCharSequence- Overrides:
toStringin classObject
-