31
31
* Netty {@link ByteBufAllocator}.
32
32
*
33
33
* @author Arjen Poutsma
34
+ * @author Juergen Hoeller
34
35
* @since 5.0
35
36
* @see io.netty.buffer.PooledByteBufAllocator
36
37
* @see io.netty.buffer.UnpooledByteBufAllocator
@@ -47,7 +48,7 @@ public class NettyDataBufferFactory implements DataBufferFactory {
47
48
* @see io.netty.buffer.UnpooledByteBufAllocator
48
49
*/
49
50
public NettyDataBufferFactory (ByteBufAllocator byteBufAllocator ) {
50
- Assert .notNull (byteBufAllocator , "'byteBufAllocator' must not be null" );
51
+ Assert .notNull (byteBufAllocator , "ByteBufAllocator must not be null" );
51
52
this .byteBufAllocator = byteBufAllocator ;
52
53
}
53
54
@@ -97,8 +98,12 @@ public NettyDataBuffer wrap(ByteBuf byteBuf) {
97
98
*/
98
99
@ Override
99
100
public DataBuffer join (List <? extends DataBuffer > dataBuffers ) {
100
- Assert .notNull (dataBuffers , "'dataBuffers' must not be null" );
101
- CompositeByteBuf composite = this .byteBufAllocator .compositeBuffer (dataBuffers .size ());
101
+ Assert .notEmpty (dataBuffers , "DataBuffer List must not be empty" );
102
+ int bufferCount = dataBuffers .size ();
103
+ if (bufferCount == 1 ) {
104
+ return dataBuffers .get (0 );
105
+ }
106
+ CompositeByteBuf composite = this .byteBufAllocator .compositeBuffer (bufferCount );
102
107
for (DataBuffer dataBuffer : dataBuffers ) {
103
108
Assert .isInstanceOf (NettyDataBuffer .class , dataBuffer );
104
109
composite .addComponent (true , ((NettyDataBuffer ) dataBuffer ).getNativeBuffer ());
@@ -107,11 +112,11 @@ public DataBuffer join(List<? extends DataBuffer> dataBuffers) {
107
112
}
108
113
109
114
/**
110
- * Return the given Netty {@link DataBuffer} as a {@link ByteBuf}. Returns the
111
- * {@linkplain NettyDataBuffer#getNativeBuffer() native buffer} if {@code buffer} is
112
- * a {@link NettyDataBuffer}; returns {@link Unpooled#wrappedBuffer(ByteBuffer)}
113
- * otherwise.
114
- * @param buffer the {@code DataBuffer} to return a {@code ByteBuf} for.
115
+ * Return the given Netty {@link DataBuffer} as a {@link ByteBuf}.
116
+ * <p>Returns the {@linkplain NettyDataBuffer#getNativeBuffer() native buffer}
117
+ * if {@code buffer} is a {@link NettyDataBuffer}; returns
118
+ * {@link Unpooled#wrappedBuffer(ByteBuffer)} otherwise.
119
+ * @param buffer the {@code DataBuffer} to return a {@code ByteBuf} for
115
120
* @return the netty {@code ByteBuf}
116
121
*/
117
122
public static ByteBuf toByteBuf (DataBuffer buffer ) {
0 commit comments