public class BufferAllocator extends FilterAllocator implements Buffer
BufferAllocator
object is used to provide a means
to allocate buffers using a single underlying buffer. This uses a
buffer from a existing allocator to create the region of memory to
use to allocate all other buffers. As a result this allows a single
buffer to acquire the bytes in a number of associated buffers. This
has the advantage of allowing bytes to be read in sequence without
joining data from other buffers or allocating multiple regions.capacity, limit, source
Constructor and Description |
---|
BufferAllocator(Allocator source)
Constructor for the
BufferAllocator object. |
BufferAllocator(Allocator source,
int capacity)
Constructor for the
BufferAllocator object. |
BufferAllocator(Allocator source,
int capacity,
int limit)
Constructor for the
BufferAllocator object. |
Modifier and Type | Method and Description |
---|---|
Buffer |
allocate()
This method is used to allocate a default buffer.
|
Buffer |
allocate(int size)
This method is used to allocate a default buffer.
|
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 a buffer can be represented as a
stream of bytes.
|
public BufferAllocator(Allocator source)
BufferAllocator
object. This is
used to instantiate the allocator with a default buffer size of
half a kilobyte. This ensures that it can be used for general
purpose byte storage and for minor I/O tasks.source
- this is where the underlying buffer is allocatedpublic BufferAllocator(Allocator source, int capacity)
BufferAllocator
object. This is
used to instantiate the allocator with a specified buffer size.
This is typically used when a very specific buffer capacity is
required, for example a request body with a known length.source
- this is where the underlying buffer is allocatedcapacity
- the initial capacity of the allocated bufferspublic BufferAllocator(Allocator source, int capacity, int limit)
BufferAllocator
object. This is
used to instantiate the allocator with a specified buffer size.
This is typically used when a very specific buffer capacity is
required, for example a request body with a known length.source
- this is where the underlying buffer is allocatedcapacity
- the initial capacity of the allocated bufferslimit
- this is the maximum buffer size created by thispublic java.io.InputStream getInputStream() throws java.io.IOException
getInputStream
in interface Stream
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
append
in interface Buffer
array
- this is the byte array to append to this buffersize
- the number of bytes to be read from the arrayoff
- this is the offset to begin reading the bytes fromjava.io.IOException
public void clear() throws java.io.IOException
public void close() throws java.io.IOException
public Buffer allocate() throws java.io.IOException
public Buffer allocate(int size) throws java.io.IOException
allocate
in interface Allocator
allocate
in class FilterAllocator
size
- the initial capacity of the allocated bufferjava.io.IOException