Top Description Fields Constructors Methods
org.apache.http.util

public final Class CharArrayBuffer

extends Object
implements CharSequence, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, java.lang.CharSequence
Imports
java.io.Serializable, java.nio.CharBuffer, org.apache.http.protocol.HTTP

A resizable char array.
Since
4.0

Field Summary

Modifier and TypeField and Description
private char[]
private int
private static final long

Constructor Summary

AccessConstructor and Description
public
CharArrayBuffer(final int
the capacity
capacity
)

Creates an instance of CharArrayBuffer with the given initial capacity.

Method Summary

Modifier and TypeMethod and Description
public void
append(final char[]
the chars to be appended.
b
,
final int
the index of the first char to append.
off
,
final int
the number of chars to append.
len
)

Appends len chars to this buffer from the given source array starting at index off.

public void
append(final String
the string.
str
)

Appends chars of the given string to this buffer.

public void
append(final CharArrayBuffer
the source buffer to be appended.
b
,
final int
the index of the first char to append.
off
,
final int
the number of chars to append.
len
)

Appends len chars to this buffer from the given source buffer starting at index off.

public void
append(final CharArrayBuffer
the source buffer to be appended.
b
)

Appends all chars to this buffer from the given source buffer starting at index 0.

public void
append(final char
the char to be appended.
ch
)

Appends ch char to this buffer.

public void
append(final byte[]
the bytes to be appended.
b
,
final int
the index of the first byte to append.
off
,
final int
the number of bytes to append.
len
)

Appends len bytes to this buffer from the given source array starting at index off.

public void
append(final ByteArrayBuffer
the bytes to be appended.
b
,
final int
the index of the first byte to append.
off
,
final int
the number of bytes to append.
len
)

Appends len bytes to this buffer from the given source array starting at index off.

public void
append(final Object
the object.
obj
)

Appends chars of the textual representation of the given object to this buffer.

public char[]

Returns:

the char array.
buffer
()

Returns reference to the underlying char array.

public int

Returns:

the current capacity
capacity
()

Returns the current capacity.

public char

Returns:

the char value at the specified index.
charAt
(final int
the index of the desired char value.
i
)

Implements java.lang.CharSequence.charAt.

Returns the char value in this buffer at the specified index.
public void
clear()

Clears content of the buffer.

public void
ensureCapacity(final int
the minimum required capacity.
required
)

Ensures that the capacity is at least equal to the specified minimum.

private void
expand(final int newlen)

public int

Returns:

the index of the first occurrence of the character in the buffer within the given bounds, or -1 if the character does not occur.
indexOf
(final int
the char to search for.
ch
,
final int
the index to start the search from.
from
,
final int
the index to finish the search at.
to
)

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.

public int

Returns:

the index of the first occurrence of the character in the buffer, or -1 if the character does not occur.
indexOf
(final int
the char to search for.
ch
)

Returns the index within this buffer of the first occurrence of the specified character, starting the search at 0 and finishing at length().

public boolean

Returns:

true if this buffer is empty, false otherwise.
isEmpty
()

Overrides default java.lang.CharSequence.isEmpty.

Returns true if this buffer is empty, that is, its length() is equal to 0.
public boolean

Returns:

true if this buffer is full, false otherwise.
isFull
()

Returns true if this buffer is full, that is, its length() is equal to its capacity().

public int

Returns:

the length of the buffer
length
()

Implements java.lang.CharSequence.length.

Returns the length of the buffer (char count).
public void
setLength(final int
the new length
len
)

Sets the length of the buffer.

public CharSequence
subSequence(final int
the start index, inclusive
beginIndex
,
final int
the end index, exclusive
endIndex
)

Implements java.lang.CharSequence.subSequence.

Returns a CharSequence that is a subsequence of this sequence.
public String

Returns:

the specified substring.
substring
(final int
the beginning index, inclusive.
beginIndex
,
final int
the ending index, exclusive.
endIndex
)

Returns a substring of this buffer.

public String

Returns:

the specified substring.
substringTrimmed
(final int
the beginning index, inclusive.
beginIndex
,
final int
the ending index, exclusive.
endIndex
)

Returns a substring of this buffer with leading and trailing whitespace omitted.

public char[]

Returns:

char array
toCharArray
()

Converts the content of this buffer to an array of chars.

public String
toString()

Overrides java.lang.Object.toString.

Implements java.lang.CharSequence.toString.

Returns a string containing the characters in this sequence in the same order as this sequence.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

bufferback to summary
private char[] buffer
lenback to summary
private int len
serialVersionUIDback to summary
private static final long serialVersionUID

Constructor Detail

CharArrayBufferback to summary
public CharArrayBuffer(final int capacity)

Creates an instance of CharArrayBuffer with the given initial capacity.

Parameters
capacity:int

the capacity

Method Detail

appendback to summary
public void append(final char[] b, final int off, final int len)

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.

Parameters
b:char[]

the chars to be appended.

off:int

the index of the first char to append.

len:int

the number of chars to append.

Exceptions
IndexOutOfBoundsException:
if off is out of range, len is negative, or off + len is out of range.
appendback to summary
public void append(final String str)

Appends chars of the given string to this buffer. The capacity of the buffer is increased, if necessary, to accommodate all chars.

Parameters
str:String

the string.

appendback to summary
public void append(final CharArrayBuffer b, final int off, final int 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.

Parameters
b:CharArrayBuffer

the source buffer to be appended.

off:int

the index of the first char to append.

len:int

the number of chars to append.

Exceptions
IndexOutOfBoundsException:
if off is out of range, len is negative, or off + len is out of range.
appendback to summary
public void append(final CharArrayBuffer b)

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.

Parameters
b:CharArrayBuffer

the source buffer to be appended.

appendback to summary
public void append(final char ch)

Appends ch char to this buffer. The capacity of the buffer is increased, if necessary, to accommodate the additional char.

Parameters
ch:char

the char to be appended.

appendback to summary
public void append(final byte[] b, final int off, final int len)

Appends len bytes 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 bytes.

The bytes are converted to chars using simple cast.

Parameters
b:byte[]

the bytes to be appended.

off:int

the index of the first byte to append.

len:int

the number of bytes to append.

Exceptions
IndexOutOfBoundsException:
if off is out of range, len is negative, or off + len is out of range.
appendback to summary
public void append(final ByteArrayBuffer b, final int off, final int len)

Appends len bytes 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 bytes.

The bytes are converted to chars using simple cast.

Parameters
b:ByteArrayBuffer

the bytes to be appended.

off:int

the index of the first byte to append.

len:int

the number of bytes to append.

Exceptions
IndexOutOfBoundsException:
if off is out of range, len is negative, or off + len is out of range.
appendback to summary
public void append(final Object 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.

Parameters
obj:Object

the object.

bufferback to summary
public char[] buffer()

Returns reference to the underlying char array.

Returns:char[]

the char array.

capacityback to summary
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:int

the current capacity

charAtback to summary
public char charAt(final int i)

Implements java.lang.CharSequence.charAt.

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.

Parameters
i:int

the index of the desired char value.

Returns:char

the char value at the specified index.

Annotations
@Override
Exceptions
IndexOutOfBoundsException:
if index is negative or greater than or equal to length().
clearback to summary
public void clear()

Clears content of the buffer. The underlying char array is not resized.

ensureCapacityback to summary
public void ensureCapacity(final 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 the required argument is non-positive, this method takes no action.

Parameters
required:int

the minimum required capacity.

expandback to summary
private void expand(final int newlen)
indexOfback to summary
public int indexOf(final int ch, final int from, final int to)

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.

Parameters
ch:int

the char to search for.

from:int

the index to start the search from.

to:int

the index to finish the search at.

Returns:int

the index of the first occurrence of the character in the buffer within the given bounds, or -1 if the character does not occur.

indexOfback to summary
public int indexOf(final int ch)

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.

Parameters
ch:int

the char to search for.

Returns:int

the index of the first occurrence of the character in the buffer, or -1 if the character does not occur.

isEmptyback to summary
public boolean isEmpty()

Overrides default java.lang.CharSequence.isEmpty.

Returns true if this buffer is empty, that is, its length() is equal to 0.

Returns:boolean

true if this buffer is empty, false otherwise.

isFullback to summary
public boolean isFull()

Returns true if this buffer is full, that is, its length() is equal to its capacity().

Returns:boolean

true if this buffer is full, false otherwise.

lengthback to summary
public int length()

Implements java.lang.CharSequence.length.

Returns the length of the buffer (char count).

Returns:int

the length of the buffer

Annotations
@Override
setLengthback to summary
public void setLength(final 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 to 0.

Parameters
len:int

the new length

Exceptions
IndexOutOfBoundsException:
if the len argument is greater than the current capacity of the buffer or less than 0.
subSequenceback to summary
public CharSequence subSequence(final int beginIndex, final int endIndex)

Implements java.lang.CharSequence.subSequence.

Doc from java.lang.CharSequence.subSequence.

Returns a CharSequence that is a subsequence of this sequence. The subsequence starts with the char value at the specified index and ends with the char value at index end - 1. The length (in chars) of the returned sequence is end - start, so if start == end then an empty sequence is returned.

Parameters
beginIndex:int

the start index, inclusive

endIndex:int

the end index, exclusive

Returns:CharSequence

the specified subsequence

Annotations
@Override
Since
4.4
substringback to summary
public String substring(final int beginIndex, final int endIndex)

Returns a substring of this buffer. The substring begins at the specified beginIndex and extends to the character at index endIndex - 1.

Parameters
beginIndex:int

the beginning index, inclusive.

endIndex:int

the ending index, exclusive.

Returns:String

the specified substring.

Exceptions
StringIndexOutOfBoundsException:
if the beginIndex is negative, or endIndex is larger than the length of this buffer, or beginIndex is larger than endIndex.
substringTrimmedback to summary
public String substringTrimmed(final int beginIndex, final int endIndex)

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.

Parameters
beginIndex:int

the beginning index, inclusive.

endIndex:int

the ending index, exclusive.

Returns:String

the specified substring.

Exceptions
IndexOutOfBoundsException:
if the beginIndex is negative, or endIndex is larger than the length of this buffer, or beginIndex is larger than endIndex.
toCharArrayback to summary
public char[] toCharArray()

Converts the content of this buffer to an array of chars.

Returns:char[]

char array

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Implements java.lang.CharSequence.toString.

Doc from java.lang.CharSequence.toString.

Returns a string containing the characters in this sequence in the same order as this sequence. The length of the string will be the length of this sequence.

Returns:String

a string consisting of exactly this sequence of characters

Annotations
@Override