A resizable char array.
| Method from org.apache.http.util.CharArrayBuffer Detail: |
public void append(String str) {
if (str == null) {
str = "null";
}
int strlen = str.length();
int newlen = this.len + strlen;
if (newlen > this.buffer.length) {
expand(newlen);
}
str.getChars(0, strlen, this.buffer, this.len);
this.len = newlen;
}
Appends chars of the given string to this buffer. The capacity of the
buffer is increased, if necessary, to accommodate all chars. |
public void append(CharArrayBuffer b) {
if (b == null) {
return;
}
append(b.buffer,0, b.len);
}
Appends all chars to this buffer from the given source buffer starting
at index 0. The capacity of the destination buffer is
increased, if necessary, to accommodate all #length() chars. |
public void append(char ch) {
int newlen = this.len + 1;
if (newlen > this.buffer.length) {
expand(newlen);
}
this.buffer[this.len] = ch;
this.len = newlen;
}
Appends ch char to this buffer. The capacity of the buffer
is increased, if necessary, to accommodate the additional char. |
public void append(Object obj) {
append(String.valueOf(obj));
}
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. |
public void append(char[] b,
int off,
int len) {
if (b == null) {
return;
}
if ((off < 0) || (off > b.length) || (len < 0) ||
((off + len) < 0) || ((off + len) > b.length)) {
throw new IndexOutOfBoundsException();
}
if (len == 0) {
return;
}
int newlen = this.len + len;
if (newlen > this.buffer.length) {
expand(newlen);
}
System.arraycopy(b, off, this.buffer, this.len, len);
this.len = newlen;
}
Appends len chars to this buffer from the given source
array starting at index off. The capacity of the buffer
is increased, if necessary, to accommodate all len chars. |
public void append(CharArrayBuffer b,
int off,
int len) {
if (b == null) {
return;
}
append(b.buffer, off, len);
}
Appends len chars to this buffer from the given source
buffer starting at index off. The capacity of the
destination buffer is increased, if necessary, to accommodate all
len chars. |
public void append(byte[] b,
int off,
int len) {
if (b == null) {
return;
}
if ((off < 0) || (off > b.length) || (len < 0) ||
((off + len) < 0) || ((off + len) > b.length)) {
throw new IndexOutOfBoundsException();
}
if (len == 0) {
return;
}
int oldlen = this.len;
int newlen = oldlen + len;
if (newlen > this.buffer.length) {
expand(newlen);
}
for (int i1 = off, i2 = oldlen; i2 < newlen; i1++, i2++) {
this.buffer[i2] = (char) (b[i1] & 0xff);
}
this.len = newlen;
}
|
public void append(ByteArrayBuffer b,
int off,
int len) {
if (b == null) {
return;
}
append(b.buffer(), off, len);
}
|
public char[] buffer() {
return this.buffer;
}
Returns reference to the underlying char array. |
public int capacity() {
return this.buffer.length;
}
Returns the current capacity. The capacity is the amount of storage
available for newly appended chars, beyond which an allocation will
occur. |
public char charAt(int i) {
return this.buffer[i];
}
Returns the char value in this buffer at the specified
index. The index argument must be greater than or equal to
0, and less than the length of this buffer. |
public void clear() {
this.len = 0;
}
Clears content of the buffer. The underlying char array is not resized. |
public void ensureCapacity(int required) {
if (required < = 0) {
return;
}
int available = this.buffer.length - this.len;
if (required > available) {
expand(this.len + 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 the required
argument is non-positive, this method takes no action. |
public int indexOf(int ch) {
return indexOf(ch, 0, this.len);
}
Returns the index within this buffer of the first occurrence of the
specified character, starting the search at 0 and finishing
at #length() . If no such character occurs in this buffer within
those bounds, -1 is returned. |
public int indexOf(int ch,
int beginIndex,
int endIndex) {
if (beginIndex < 0) {
beginIndex = 0;
}
if (endIndex > this.len) {
endIndex = this.len;
}
if (beginIndex > endIndex) {
return -1;
}
for (int i = beginIndex; i < endIndex; i++) {
if (this.buffer[i] == ch) {
return i;
}
}
return -1;
}
Returns the index within this buffer of the first occurrence of the
specified character, starting the search at the specified
beginIndex and finishing at endIndex.
If no such character occurs in this buffer within the specified bounds,
-1 is returned.
There is no restriction on the value of beginIndex and
endIndex. If beginIndex is negative,
it has the same effect as if it were zero. If endIndex is
greater than #length() , it has the same effect as if it were
#length() . If the beginIndex is greater than
the endIndex, -1 is returned. |
public boolean isEmpty() {
return this.len == 0;
}
Returns true if this buffer is empty, that is, its
#length() is equal to 0. |
public boolean isFull() {
return this.len == this.buffer.length;
}
|
public int length() {
return this.len;
}
Returns the length of the buffer (char count). |
public void setLength(int len) {
if (len < 0 || len > this.buffer.length) {
throw new IndexOutOfBoundsException();
}
this.len = 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 to
0. |
public String substring(int beginIndex,
int endIndex) {
if (beginIndex < 0) {
throw new IndexOutOfBoundsException();
}
if (endIndex > this.len) {
throw new IndexOutOfBoundsException();
}
if (beginIndex > endIndex) {
throw new IndexOutOfBoundsException();
}
return new String(this.buffer, beginIndex, endIndex - beginIndex);
}
Returns a substring of this buffer. The substring begins at the specified
beginIndex and extends to the character at index
endIndex - 1. |
public String substringTrimmed(int beginIndex,
int endIndex) {
if (beginIndex < 0) {
throw new IndexOutOfBoundsException();
}
if (endIndex > this.len) {
throw new IndexOutOfBoundsException();
}
if (beginIndex > endIndex) {
throw new IndexOutOfBoundsException();
}
while (beginIndex < endIndex && HTTP.isWhitespace(this.buffer[beginIndex])) {
beginIndex++;
}
while (endIndex > beginIndex && HTTP.isWhitespace(this.buffer[endIndex - 1])) {
endIndex--;
}
return new String(this.buffer, beginIndex, endIndex - beginIndex);
}
Returns a substring of this buffer with leading and trailing whitespace
omitted. The substring begins with the first non-whitespace character
from beginIndex and extends to the last
non-whitespace character with the index lesser than
endIndex. |
public char[] toCharArray() {
char[] b = new char[this.len];
if (this.len > 0) {
System.arraycopy(this.buffer, 0, b, 0, this.len);
}
return b;
}
Converts the content of this buffer to an array of chars. |
public String toString() {
return new String(this.buffer, 0, this.len);
}
|