public class ArrayBuffer extends 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.
|
String |
encode()
This method is used to acquire the buffered bytes as a string.
|
String |
encode(String charset)
This method is used to acquire the buffered bytes as a string.
|
long |
length()
This is used to provide the number of bytes that have been
written to the buffer.
|
InputStream |
open()
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 InputStream open()
public Buffer allocate() throws IOException
allocate
in interface Buffer
IOException
public String encode() throws IOException
encode
in interface Buffer
IOException
public String encode(String charset) throws IOException
encode
in interface Buffer
charset
- this is the charset to encode the data withIOException
public Buffer append(byte[] array) throws IOException
append
in interface Buffer
array
- this is the byte array to append to this bufferIOException
public Buffer append(byte[] array, int off, int size) throws IOException
append
in interface Buffer
array
- this is the byte array to append to this bufferoff
- this is the offset to begin reading the bytes fromsize
- the number of bytes to be read from the arrayIOException
public void clear() throws IOException
clear
in interface Buffer
IOException
public void close() throws IOException
close
in interface Buffer
IOException
public long length()
Copyright © 2021. All rights reserved.