- All Known Implementing Classes:
DefaultDataBufferFactory
public interface DataBufferFactory
A factory for
DataBuffers
, allowing for allocation and wrapping of data
buffers.- Since:
- 5.0
- Author:
- Arjen Poutsma
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionAllocate a data buffer of a default initial capacity.allocateBuffer
(int initialCapacity) Allocate a data buffer of the given initial capacity.int
Buffer of a default initial capacity.boolean
isDirect()
Indicates whether this factory allocates direct buffers (i.e.join
(List<? extends DataBuffer> dataBuffers) Return a newDataBuffer
composed of thedataBuffers
elements joined together.setDefaultInitialCapacity
(int defaultInitialCapacity) Set default buffer initial capacity.wrap
(byte[] bytes) Wrap the givenbyte
array in aDataBuffer
.wrap
(byte[] bytes, int offset, int length) Wrap the givenbyte
array in aDataBuffer
.wrap
(ByteBuffer byteBuffer) Wrap the givenByteBuffer
in aDataBuffer
.
-
Method Details
-
getDefaultInitialCapacity
int getDefaultInitialCapacity()Buffer of a default initial capacity. Default capacity is1024
bytes.- Returns:
- buffer of a default initial capacity.
-
setDefaultInitialCapacity
Set default buffer initial capacity.- Parameters:
defaultInitialCapacity
- Default initial buffer capacity.- Returns:
- This buffer factory.
-
allocateBuffer
DataBuffer allocateBuffer()Allocate a data buffer of a default initial capacity. Depending on the underlying implementation and its configuration, this will be heap-based or direct buffer.- Returns:
- the allocated buffer
-
allocateBuffer
Allocate a data buffer of the given initial capacity. Depending on the underlying implementation and its configuration, this will be heap-based or direct buffer.- Parameters:
initialCapacity
- the initial capacity of the buffer to allocate- Returns:
- the allocated buffer
-
wrap
- Parameters:
byteBuffer
- the NIO byte buffer to wrap- Returns:
- the wrapped buffer
-
wrap
- Parameters:
bytes
- the byte array to wrap- Returns:
- the wrapped buffer
-
wrap
- Parameters:
bytes
- the byte array to wrap- Returns:
- the wrapped buffer
-
join
Return a newDataBuffer
composed of thedataBuffers
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.
- Parameters:
dataBuffers
- the data buffers to be composed- Returns:
- a buffer that is composed of the
dataBuffers
argument - Since:
- 5.0.3
-
isDirect
boolean isDirect()Indicates whether this factory allocates direct buffers (i.e. non-heap, native memory).- Returns:
true
if this factory allocates direct buffers;false
otherwise- Since:
- 6.0
-