public class NettyDataBufferFactory extends Object implements DataBufferFactory
DataBufferFactory
interface based on a
Netty ByteBufAllocator
.PooledByteBufAllocator
,
UnpooledByteBufAllocator
Constructor and Description |
---|
NettyDataBufferFactory(io.netty.buffer.ByteBufAllocator byteBufAllocator)
Create a new
NettyDataBufferFactory based on the given factory. |
Modifier and Type | Method and Description |
---|---|
NettyDataBuffer |
allocateBuffer()
Allocate a data buffer of a default initial capacity.
|
NettyDataBuffer |
allocateBuffer(int initialCapacity)
Allocate a data buffer of the given initial capacity.
|
io.netty.buffer.ByteBufAllocator |
getByteBufAllocator()
Return the
ByteBufAllocator used by this factory. |
DataBuffer |
join(List<? extends DataBuffer> dataBuffers)
Return a new
DataBuffer composed of the dataBuffers elements joined together. |
static io.netty.buffer.ByteBuf |
toByteBuf(DataBuffer buffer)
Return the given Netty
DataBuffer as a ByteBuf . |
String |
toString() |
DataBuffer |
wrap(byte[] bytes)
Wrap the given
byte array in a DataBuffer . |
NettyDataBuffer |
wrap(io.netty.buffer.ByteBuf byteBuf)
Wrap the given Netty
ByteBuf in a NettyDataBuffer . |
NettyDataBuffer |
wrap(ByteBuffer byteBuffer)
Wrap the given
ByteBuffer in a DataBuffer . |
public NettyDataBufferFactory(io.netty.buffer.ByteBufAllocator byteBufAllocator)
NettyDataBufferFactory
based on the given factory.byteBufAllocator
- the factory to usePooledByteBufAllocator
,
UnpooledByteBufAllocator
public io.netty.buffer.ByteBufAllocator getByteBufAllocator()
ByteBufAllocator
used by this factory.public NettyDataBuffer allocateBuffer()
DataBufferFactory
allocateBuffer
in interface DataBufferFactory
public NettyDataBuffer allocateBuffer(int initialCapacity)
DataBufferFactory
allocateBuffer
in interface DataBufferFactory
initialCapacity
- the initial capacity of the buffer to allocatepublic NettyDataBuffer wrap(ByteBuffer byteBuffer)
DataBufferFactory
wrap
in interface DataBufferFactory
byteBuffer
- the NIO byte buffer to wrappublic DataBuffer wrap(byte[] bytes)
DataBufferFactory
wrap
in interface DataBufferFactory
bytes
- the byte array to wrappublic NettyDataBuffer wrap(io.netty.buffer.ByteBuf byteBuf)
ByteBuf
in a NettyDataBuffer
.byteBuf
- the Netty byte buffer to wrappublic DataBuffer 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 uses Netty's CompositeByteBuf
.
join
in interface DataBufferFactory
dataBuffers
- the data buffers to be composeddataBuffers
argumentpublic static io.netty.buffer.ByteBuf toByteBuf(DataBuffer buffer)
DataBuffer
as a ByteBuf
.
Returns the native buffer
if buffer
is a NettyDataBuffer
; returns
Unpooled.wrappedBuffer(ByteBuffer)
otherwise.
buffer
- the DataBuffer
to return a ByteBuf
forByteBuf