org.freecompany.util.text
Class ByteBufferWrapper
public
class
ByteBufferWrapper
extends Object
implements CharSequence
This class provides a wrapper view of a buffer of bytes as a sequence
of US-ASCII characters. This is appropriate for treating a buffer of bytes
like a buffer of characters when it is known that it contains only 7 bit
characters.
Method Summary |
char | charAt(int index)
Returns the character at the provided index in the backing byte buffer, respective of
the current buffer position. |
ByteBuffer | getBuffer() |
int | length()
Returns the perceived length of this character sequence, which in this case is the number
of bytes between the position and limit of the backing buffer. |
CharSequence | subSequence(int start, int end)
Creates a new wrapped slice of the buffer given position and limit values
derived from the provided start and end indexes. |
String | toString()
Creates a UTF-8 decoded string representation of this byte buffer. |
protected final ByteBuffer buffer
public ByteBufferWrapper(ByteBuffer buffer)
public char charAt(int index)
Returns the character at the provided index in the backing byte buffer, respective of
the current buffer position.
public ByteBuffer getBuffer()
public int length()
Returns the perceived length of this character sequence, which in this case is the number
of bytes between the position and limit of the backing buffer.
public CharSequence subSequence(int start, int end)
Creates a new wrapped slice of the buffer given position and limit values
derived from the provided start and end indexes. After slicing, the underlying
buffer is reset to it's original position and limit, but as the temporary changes
are not atomic care must be taken not to depend on the state of the backing buffer
being consistent during this call. In other words, the buffer is not safe for access
by other threads while this method is executing.
public String toString()
Creates a UTF-8 decoded string representation of this byte buffer. Teh behavior is undefined
if the backing buffer contains any non US-ASCII characters. This method is implemented to build
a string one character at a time and so may be prohibitively slow for large buffers.