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)
Creates 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.
|
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 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
ByteBuffer
in a DataBuffer
.wrap
in interface DataBufferFactory
byteBuffer
- the NIO byte buffer to wrappublic DataBuffer wrap(byte[] bytes)
DataBufferFactory
byte
array in a DataBuffer
.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 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
for.ByteBuf