Top Description Fields Constructors Methods
org.springframework.core.io.buffer

public Class NettyDataBufferFactory

extends Object
implements DataBufferFactory
Class Inheritance
All Implemented Interfaces
org.springframework.core.io.buffer.DataBufferFactory
Imports
java.nio.ByteBuffer, java.util.List, io.netty.buffer.ByteBuf, .ByteBufAllocator, .CompositeByteBuf, .Unpooled, org.springframework.util.Assert

Implementation of the DataBufferFactory interface based on a Netty 4 ByteBufAllocator.
Authors
Arjen Poutsma, Juergen Hoeller
Since
5.0
See Also
io.netty.buffer.PooledByteBufAllocator, io.netty.buffer.UnpooledByteBufAllocator

Field Summary

Modifier and TypeField and Description
private final ByteBufAllocator

Constructor Summary

AccessConstructor and Description
public
NettyDataBufferFactory(ByteBufAllocator
the factory to use
byteBufAllocator
)

Create a new NettyDataBufferFactory based on the given factory.

Method Summary

Modifier and TypeMethod and Description
public NettyDataBuffer
allocateBuffer()

Implements org.springframework.core.io.buffer.DataBufferFactory.allocateBuffer.

Deprecated
Allocate a data buffer of a default initial capacity.
public NettyDataBuffer
allocateBuffer(int
the initial capacity of the buffer to allocate
initialCapacity
)

Implements org.springframework.core.io.buffer.DataBufferFactory.allocateBuffer.

Allocate a data buffer of the given initial capacity.
public ByteBufAllocator
getByteBufAllocator()

Return the ByteBufAllocator used by this factory.

public boolean
isDirect()

Implements org.springframework.core.io.buffer.DataBufferFactory.isDirect.

Indicates whether this factory allocates direct buffers (i.e. non-heap, native memory).
public DataBuffer
join(List<? extends DataBuffer>
the data buffers to be composed
dataBuffers
)

Implements org.springframework.core.io.buffer.DataBufferFactory.join.

Return a new DataBuffer composed of the dataBuffers elements joined together.
public static ByteBuf

Returns:

the netty ByteBuf
toByteBuf
(DataBuffer
the DataBuffer to return a ByteBuf for
dataBuffer
)

Return the given Netty DataBuffer as a ByteBuf.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public NettyDataBuffer
wrap(ByteBuffer
the NIO byte buffer to wrap
byteBuffer
)

Implements org.springframework.core.io.buffer.DataBufferFactory.wrap.

Wrap the given ByteBuffer in a DataBuffer.
public DataBuffer
wrap(byte[]
the byte array to wrap
bytes
)

Implements org.springframework.core.io.buffer.DataBufferFactory.wrap.

Wrap the given byte array in a DataBuffer.
public NettyDataBuffer

Returns:

the wrapped buffer
wrap
(ByteBuf
the Netty byte buffer to wrap
byteBuf
)

Wrap the given Netty ByteBuf in a NettyDataBuffer.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

byteBufAllocatorback to summary
private final ByteBufAllocator byteBufAllocator

Constructor Detail

NettyDataBufferFactoryback to summary
public NettyDataBufferFactory(ByteBufAllocator byteBufAllocator)

Create a new NettyDataBufferFactory based on the given factory.

Parameters
byteBufAllocator:ByteBufAllocator

the factory to use

See Also
io.netty.buffer.PooledByteBufAllocator, io.netty.buffer.UnpooledByteBufAllocator

Method Detail

allocateBufferback to summary
public NettyDataBuffer allocateBuffer()

Implements org.springframework.core.io.buffer.DataBufferFactory.allocateBuffer.

Doc from org.springframework.core.io.buffer.DataBufferFactory.allocateBuffer.

Deprecated

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:NettyDataBuffer

the allocated buffer

Annotations
@Override
@Deprecated
allocateBufferback to summary
public NettyDataBuffer allocateBuffer(int initialCapacity)

Implements org.springframework.core.io.buffer.DataBufferFactory.allocateBuffer.

Doc from org.springframework.core.io.buffer.DataBufferFactory.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:int

the initial capacity of the buffer to allocate

Returns:NettyDataBuffer

the allocated buffer

Annotations
@Override
getByteBufAllocatorback to summary
public ByteBufAllocator getByteBufAllocator()

Return the ByteBufAllocator used by this factory.

isDirectback to summary
public boolean isDirect()

Implements org.springframework.core.io.buffer.DataBufferFactory.isDirect.

Doc from org.springframework.core.io.buffer.DataBufferFactory.isDirect.

Indicates whether this factory allocates direct buffers (i.e. non-heap, native memory).

Returns:boolean

true if this factory allocates direct buffers; false otherwise

Annotations
@Override
joinback to summary
public DataBuffer join(List<? extends DataBuffer> dataBuffers)

Implements org.springframework.core.io.buffer.DataBufferFactory.join.

Doc from org.springframework.core.io.buffer.DataBufferFactory.join.

Return a new 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.

Parameters
dataBuffers:List<? extends DataBuffer>

the data buffers to be composed

Returns:DataBuffer

a buffer that is composed of the dataBuffers argument

Annotations
@Override
toByteBufback to summary
public static ByteBuf toByteBuf(DataBuffer dataBuffer)

Return the given Netty DataBuffer as a ByteBuf.

Returns the native buffer if dataBuffer is a NettyDataBuffer; returns Unpooled#wrappedBuffer(ByteBuffer) otherwise.

Parameters
dataBuffer:DataBuffer

the DataBuffer to return a ByteBuf for

Returns:ByteBuf

the netty ByteBuf

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
wrapback to summary
public NettyDataBuffer wrap(ByteBuffer byteBuffer)

Implements org.springframework.core.io.buffer.DataBufferFactory.wrap.

Doc from org.springframework.core.io.buffer.DataBufferFactory.wrap.

Wrap the given ByteBuffer in a DataBuffer. Unlike allocating, wrapping does not use new memory.

Parameters
byteBuffer:ByteBuffer

the NIO byte buffer to wrap

Returns:NettyDataBuffer

the wrapped buffer

Annotations
@Override
wrapback to summary
public DataBuffer wrap(byte[] bytes)

Implements org.springframework.core.io.buffer.DataBufferFactory.wrap.

Doc from org.springframework.core.io.buffer.DataBufferFactory.wrap.

Wrap the given byte array in a DataBuffer. Unlike allocating, wrapping does not use new memory.

Parameters
bytes:byte[]

the byte array to wrap

Returns:DataBuffer

the wrapped buffer

Annotations
@Override
wrapback to summary
public NettyDataBuffer wrap(ByteBuf byteBuf)

Wrap the given Netty ByteBuf in a NettyDataBuffer.

Parameters
byteBuf:ByteBuf

the Netty byte buffer to wrap

Returns:NettyDataBuffer

the wrapped buffer