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,
long capacity)
Constructor for the
BufferAllocator object. |
BufferAllocator(Allocator source,
long capacity,
long 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(long 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.
|
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 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, long 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, long capacity, long 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 InputStream open() throws IOException
open in interface BufferIOExceptionpublic String encode() throws IOException
encode in interface BufferIOExceptionpublic String encode(String charset) throws IOException
encode in interface Buffercharset - this is the charset to encode the data withIOExceptionpublic Buffer append(byte[] array) throws IOException
append in interface Bufferarray - this is the byte array to append to this bufferIOExceptionpublic Buffer append(byte[] array, int off, int size) throws IOException
append in interface Bufferarray - 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 fromIOExceptionpublic void clear()
throws IOException
clear in interface BufferIOExceptionpublic void close()
throws IOException
close in interface BufferIOExceptionpublic Buffer allocate() throws IOException
allocate in interface Allocatorallocate in interface Bufferallocate in class FilterAllocatorIOExceptionpublic Buffer allocate(long size) throws IOException
allocate in interface Allocatorallocate in class FilterAllocatorsize - the initial capacity of the allocated bufferIOExceptionpublic long length()
Copyright © 2025. All rights reserved.