public class FilterAllocator extends Object implements Allocator
FilterAllocator
object is used to provide a means
to provide a general set of constraints around buffer allocation.
It can ensure that a minimum capacity is used for default allocation
and that an upper limit is used for allocation. In general this can
be used in conjunction with another Allocator
which may
not have such constraints. It ensures that a set of requirements can
be observed when allocating buffers.Modifier and Type | Field and Description |
---|---|
protected long |
capacity
This is the default initial minimum capacity of the buffer.
|
protected long |
limit
This is the maximum number of bytes that can be allocated.
|
protected Allocator |
source
This is the allocator the underlying buffer is allocated with.
|
Constructor and Description |
---|
FilterAllocator(Allocator source)
Constructor for the
FilterAllocator object. |
FilterAllocator(Allocator source,
long capacity)
Constructor for the
FilterAllocator object. |
FilterAllocator(Allocator source,
long capacity,
long limit)
Constructor for the
FilterAllocator 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.
|
protected Allocator source
protected long capacity
protected long limit
public FilterAllocator(Allocator source)
FilterAllocator
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 FilterAllocator(Allocator source, long capacity)
FilterAllocator
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 FilterAllocator(Allocator source, long capacity, long limit)
FilterAllocator
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 Buffer allocate() throws IOException
allocate
in interface Allocator
IOException
public Buffer allocate(long size) throws IOException
allocate
in interface Allocator
size
- the initial capacity of the allocated bufferIOException
Copyright © 2023. All rights reserved.