public class DefaultDataBufferFactory extends Object implements DataBufferFactory
DataBufferFactory
interface. Allows for
specification of the default initial capacity at construction time, as well
as whether heap-based or direct buffers are to be preferred.Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_INITIAL_CAPACITY
The default capacity when none is specified.
|
static DefaultDataBufferFactory |
sharedInstance
Shared instance based on the default constructor.
|
Constructor and Description |
---|
DefaultDataBufferFactory()
Creates a new
DefaultDataBufferFactory with default settings. |
DefaultDataBufferFactory(boolean preferDirect)
Creates a new
DefaultDataBufferFactory , indicating whether direct
buffers should be created by allocateBuffer() and
allocateBuffer(int) . |
DefaultDataBufferFactory(boolean preferDirect,
int defaultInitialCapacity)
Creates a new
DefaultDataBufferFactory , indicating whether direct
buffers should be created by allocateBuffer() and
allocateBuffer(int) , and what the capacity is to be used for
allocateBuffer() . |
Modifier and Type | Method and Description |
---|---|
DefaultDataBuffer |
allocateBuffer()
Allocate a data buffer of a default initial capacity.
|
DefaultDataBuffer |
allocateBuffer(int initialCapacity)
Allocate a data buffer of the given initial capacity.
|
DefaultDataBuffer |
join(List<? extends DataBuffer> dataBuffers)
Return a new
DataBuffer composed of the dataBuffers elements joined together. |
String |
toString() |
DefaultDataBuffer |
wrap(byte[] bytes)
Wrap the given
byte array in a DataBuffer . |
DefaultDataBuffer |
wrap(ByteBuffer byteBuffer)
Wrap the given
ByteBuffer in a DataBuffer . |
public static final int DEFAULT_INITIAL_CAPACITY
public static final DefaultDataBufferFactory sharedInstance
public DefaultDataBufferFactory()
DefaultDataBufferFactory
with default settings.sharedInstance
public DefaultDataBufferFactory(boolean preferDirect)
DefaultDataBufferFactory
, indicating whether direct
buffers should be created by allocateBuffer()
and
allocateBuffer(int)
.preferDirect
- true
if direct buffers are to be preferred;
false
otherwisepublic DefaultDataBufferFactory(boolean preferDirect, int defaultInitialCapacity)
DefaultDataBufferFactory
, indicating whether direct
buffers should be created by allocateBuffer()
and
allocateBuffer(int)
, and what the capacity is to be used for
allocateBuffer()
.preferDirect
- true
if direct buffers are to be preferred;
false
otherwisepublic DefaultDataBuffer allocateBuffer()
DataBufferFactory
allocateBuffer
in interface DataBufferFactory
public DefaultDataBuffer allocateBuffer(int initialCapacity)
DataBufferFactory
allocateBuffer
in interface DataBufferFactory
initialCapacity
- the initial capacity of the buffer to allocatepublic DefaultDataBuffer wrap(ByteBuffer byteBuffer)
DataBufferFactory
wrap
in interface DataBufferFactory
byteBuffer
- the NIO byte buffer to wrappublic DefaultDataBuffer wrap(byte[] bytes)
DataBufferFactory
wrap
in interface DataBufferFactory
bytes
- the byte array to wrappublic DefaultDataBuffer join(List<? extends DataBuffer> dataBuffers)
DataBuffer
composed of the dataBuffers
elements joined together.
Depending on the implementation, the returned buffer may be a single buffer containing all
data of the provided buffers, or it may be a true composite that contains references to the
buffers.
Note that the given data buffers do not have to be released, as they are released as part of the returned composite.
This implementation creates a single DefaultDataBuffer
to contain the data in dataBuffers
.
join
in interface DataBufferFactory
dataBuffers
- the data buffers to be composeddataBuffers
argument