@ -31,6 +31,7 @@ import org.springframework.util.Assert;
@@ -31,6 +31,7 @@ import org.springframework.util.Assert;
* Netty { @link ByteBufAllocator } .
*
* @author Arjen Poutsma
* @author Juergen Hoeller
* @since 5 . 0
* @see io . netty . buffer . PooledByteBufAllocator
* @see io . netty . buffer . UnpooledByteBufAllocator
@ -47,7 +48,7 @@ public class NettyDataBufferFactory implements DataBufferFactory {
@@ -47,7 +48,7 @@ public class NettyDataBufferFactory implements DataBufferFactory {
* @see io . netty . buffer . UnpooledByteBufAllocator
* /
public NettyDataBufferFactory ( ByteBufAllocator byteBufAllocator ) {
Assert . notNull ( byteBufAllocator , "'byteBufAllocator' must not be null" ) ;
Assert . notNull ( byteBufAllocator , "ByteBufAllocator must not be null" ) ;
this . byteBufAllocator = byteBufAllocator ;
}
@ -82,37 +83,40 @@ public class NettyDataBufferFactory implements DataBufferFactory {
@@ -82,37 +83,40 @@ public class NettyDataBufferFactory implements DataBufferFactory {
return new NettyDataBuffer ( byteBuf , this ) ;
}
/ * *
* Wrap the given Netty { @link ByteBuf } in a { @code NettyDataBuffer } .
* @param byteBuf the Netty byte buffer to wrap
* @return the wrapped buffer
* /
public NettyDataBuffer wrap ( ByteBuf byteBuf ) {
return new NettyDataBuffer ( byteBuf , this ) ;
}
/ * *
* { @inheritDoc }
* < p > This implementation uses Netty ' s { @link CompositeByteBuf } .
* /
@Override
public DataBuffer join ( List < ? extends DataBuffer > dataBuffers ) {
Assert . notNull ( dataBuffers , "'dataBuffers' must not be null" ) ;
CompositeByteBuf composite = this . byteBufAllocator . compositeBuffer ( dataBuffers . size ( ) ) ;
Assert . notEmpty ( dataBuffers , "DataBuffer List must not be empty" ) ;
int bufferCount = dataBuffers . size ( ) ;
if ( bufferCount = = 1 ) {
return dataBuffers . get ( 0 ) ;
}
CompositeByteBuf composite = this . byteBufAllocator . compositeBuffer ( bufferCount ) ;
for ( DataBuffer dataBuffer : dataBuffers ) {
Assert . isInstanceOf ( NettyDataBuffer . class , dataBuffer ) ;
NettyDataBuffer nettyDataBuffer = ( NettyDataBuffer ) dataBuffer ;
composite . addComponent ( true , nettyDataBuffer . getNativeBuffer ( ) ) ;
composite . addComponent ( true , ( ( NettyDataBuffer ) dataBuffer ) . getNativeBuffer ( ) ) ;
}
return new NettyDataBuffer ( composite , this ) ;
}
/ * *
* Wrap the given Netty { @link ByteBuf } in a { @code NettyDataBuffer } .
* @param byteBuf the Netty byte buffer to wrap
* @return the wrapped buffer
* /
public NettyDataBuffer wrap ( ByteBuf byteBuf ) {
return new NettyDataBuffer ( byteBuf , this ) ;
}
/ * *
* Return the given Netty { @link DataBuffer } as a { @link ByteBuf } . Returns the
* { @linkplain NettyDataBuffer # getNativeBuffer ( ) native buffer } if { @code buffer } is
* a { @link NettyDataBuffer } ; returns { @link Unpooled # wrappedBuffer ( ByteBuffer ) }
* otherwise .
* @param buffer the { @code DataBuffer } to return a { @code ByteBuf } for .
* Return the given Netty { @link DataBuffer } as a { @link ByteBuf } .
* < p > Returns the { @linkplain NettyDataBuffer # getNativeBuffer ( ) native buffer }
* if { @code buffer } is a { @link NettyDataBuffer } ; returns
* { @link Unpooled # wrappedBuffer ( ByteBuffer ) } otherwise .
* @param buffer the { @code DataBuffer } to return a { @code ByteBuf } for
* @return the netty { @code ByteBuf }
* /
public static ByteBuf toByteBuf ( DataBuffer buffer ) {