public class ArrayBuffer extends java.lang.Object implements Buffer
ArrayBuffer
is intended to be a general purpose
byte buffer that stores bytes in an single internal byte array. The
intended use of this buffer is to provide a simple buffer object to
read and write bytes with. In particular this provides a high
performance buffer that can be used to read and write bytes fast.
This provides several convenience methods which make the use of the
buffer easy and useful. This buffer allows an initial capacity to be
specified however if there is a need for extra space to be added to
buffer then the append
methods will expand the capacity
of the buffer as needed.
ArrayAllocator
Constructor and Description |
---|
ArrayBuffer()
Constructor for the
ArrayBuffer object. |
ArrayBuffer(int size)
Constructor for the
ArrayBuffer object. |
ArrayBuffer(int size,
int limit)
Constructor for the
ArrayBuffer object. |
Modifier and Type | Method and Description |
---|---|
Buffer |
allocate()
This method is used to allocate a segment of this buffer as a
separate buffer object.
|
Buffer |
append(byte[] array)
This method is used to append bytes to the end of the buffer.
|
Buffer |
append(byte[] array,
int off,
int size)
This method is used to append bytes to the end of the buffer.
|
void |
clear()
This will clear all data from the buffer.
|
void |
close()
This method is used to ensure the buffer can be closed.
|
java.lang.String |
encode()
This method is used to acquire the buffered bytes as a string.
|
java.lang.String |
encode(java.lang.String charset)
This method is used to acquire the buffered bytes as a string.
|
java.io.InputStream |
getInputStream()
This method is used so that the buffer can be represented as a
stream of bytes.
|
public ArrayBuffer()
ArrayBuffer
object. The initial
capacity of the default buffer object is set to 16, the capacity
will be expanded when the append methods are used and there is
not enough space to accommodate the extra bytes.public ArrayBuffer(int size)
ArrayBuffer
object. The initial
capacity of the buffer object is set to given size, the capacity
will be expanded when the append methods are used and there is
not enough space to accommodate the extra bytes.size
- the initial capacity of this buffer instancepublic ArrayBuffer(int size, int limit)
ArrayBuffer
object. The initial
capacity of the buffer object is set to given size, the capacity
will be expanded when the append methods are used and there is
not enough space to accommodate the extra bytes.size
- the initial capacity of this buffer instancelimit
- this is the maximum allowable buffer capacitypublic java.io.InputStream getInputStream()
getInputStream
in interface Stream
public Buffer allocate() throws java.io.IOException
public java.lang.String encode() throws java.io.IOException
public java.lang.String encode(java.lang.String charset) throws java.io.IOException
public Buffer append(byte[] array) throws java.io.IOException
public Buffer append(byte[] array, int off, int size) throws java.io.IOException
public void clear() throws java.io.IOException
public void close() throws java.io.IOException