Class NettyDataBufferFactory
java.lang.Object
org.springframework.core.io.buffer.NettyDataBufferFactory
- All Implemented Interfaces:
DataBufferFactory
Implementation of the
DataBufferFactory interface based on a
Netty ByteBufAllocator.- Since:
- 5.0
- Author:
- Arjen Poutsma, Juergen Hoeller
- See Also:
-
PooledByteBufAllocatorUnpooledByteBufAllocator
-
Constructor Summary
ConstructorsConstructorDescriptionNettyDataBufferFactory(io.netty.buffer.ByteBufAllocator byteBufAllocator) Create a newNettyDataBufferFactorybased on the given factory. -
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.io.netty.buffer.ByteBufAllocatorReturn theByteBufAllocatorused by this factory.join(List<? extends DataBuffer> dataBuffers) Return a newDataBuffercomposed of thedataBufferselements joined together.static io.netty.buffer.ByteBuftoByteBuf(DataBuffer buffer) Return the given NettyDataBufferas aByteBuf.toString()wrap(byte[] bytes) Wrap the givenbytearray in aDataBuffer.wrap(io.netty.buffer.ByteBuf byteBuf) Wrap the given NettyByteBufin aNettyDataBuffer.wrap(ByteBuffer byteBuffer) Wrap the givenByteBufferin aDataBuffer.
-
Constructor Details
-
NettyDataBufferFactory
public NettyDataBufferFactory(io.netty.buffer.ByteBufAllocator byteBufAllocator) Create a newNettyDataBufferFactorybased on the given factory.- Parameters:
byteBufAllocator- the factory to use- See Also:
-
PooledByteBufAllocatorUnpooledByteBufAllocator
-
-
Method Details
-
getByteBufAllocator
public io.netty.buffer.ByteBufAllocator getByteBufAllocator()Return theByteBufAllocatorused by this factory. -
allocateBuffer
Description copied from interface:DataBufferFactoryAllocate a data buffer of a default initial capacity. Depending on the underlying implementation and its configuration, this will be heap-based or direct buffer.- Specified by:
allocateBufferin interfaceDataBufferFactory- Returns:
- the allocated buffer
-
allocateBuffer
Description copied from interface:DataBufferFactoryAllocate a data buffer of the given initial capacity. Depending on the underlying implementation and its configuration, this will be heap-based or direct buffer.- Specified by:
allocateBufferin interfaceDataBufferFactory- Parameters:
initialCapacity- the initial capacity of the buffer to allocate- Returns:
- the allocated buffer
-
wrap
Description copied from interface:DataBufferFactory- Specified by:
wrapin interfaceDataBufferFactory- Parameters:
byteBuffer- the NIO byte buffer to wrap- Returns:
- the wrapped buffer
-
wrap
Description copied from interface:DataBufferFactory- Specified by:
wrapin interfaceDataBufferFactory- Parameters:
bytes- the byte array to wrap- Returns:
- the wrapped buffer
-
wrap
Wrap the given NettyByteBufin aNettyDataBuffer.- Parameters:
byteBuf- the Netty byte buffer to wrap- Returns:
- the wrapped buffer
-
join
Return a newDataBuffercomposed of thedataBufferselements 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.- Specified by:
joinin interfaceDataBufferFactory- Parameters:
dataBuffers- the data buffers to be composed- Returns:
- a buffer that is composed from the
dataBuffersargument
-
toByteBuf
Return the given NettyDataBufferas aByteBuf.Returns the native buffer if
bufferis aNettyDataBuffer; returnsUnpooled.wrappedBuffer(ByteBuffer)otherwise.- Parameters:
buffer- theDataBufferto return aByteBuffor- Returns:
- the netty
ByteBuf
-
toString
-