27
27
import io .netty .buffer .ByteBufOutputStream ;
28
28
29
29
import org .springframework .util .Assert ;
30
+ import org .springframework .util .ObjectUtils ;
30
31
31
32
/**
32
33
* Implementation of the {@code DataBuffer} interface that wraps a Netty
@@ -43,7 +44,7 @@ public class NettyDataBuffer implements PooledDataBuffer {
43
44
44
45
45
46
/**
46
- * Creates a new {@code NettyDataBuffer} based on the given {@code ByteBuff}.
47
+ * Create a new {@code NettyDataBuffer} based on the given {@code ByteBuff}.
47
48
* @param byteBuf the buffer to base this buffer on
48
49
*/
49
50
NettyDataBuffer (ByteBuf byteBuf , NettyDataBufferFactory dataBufferFactory ) {
@@ -69,7 +70,7 @@ public NettyDataBufferFactory factory() {
69
70
70
71
@ Override
71
72
public int indexOf (IntPredicate predicate , int fromIndex ) {
72
- Assert .notNull (predicate , "'predicate' must not be null" );
73
+ Assert .notNull (predicate , "IntPredicate must not be null" );
73
74
if (fromIndex < 0 ) {
74
75
fromIndex = 0 ;
75
76
}
@@ -82,7 +83,7 @@ else if (fromIndex >= this.byteBuf.writerIndex()) {
82
83
83
84
@ Override
84
85
public int lastIndexOf (IntPredicate predicate , int fromIndex ) {
85
- Assert .notNull (predicate , "'predicate' must not be null" );
86
+ Assert .notNull (predicate , "IntPredicate must not be null" );
86
87
if (fromIndex < 0 ) {
87
88
return -1 ;
88
89
}
@@ -175,9 +176,7 @@ public NettyDataBuffer write(byte[] source, int offset, int length) {
175
176
176
177
@ Override
177
178
public NettyDataBuffer write (DataBuffer ... buffers ) {
178
- Assert .notNull (buffers , "'buffers' must not be null" );
179
-
180
- if (buffers .length > 0 ) {
179
+ if (!ObjectUtils .isEmpty (buffers )) {
181
180
if (hasNettyDataBuffers (buffers )) {
182
181
ByteBuf [] nativeBuffers = Arrays .stream (buffers )
183
182
.map (b -> ((NettyDataBuffer ) b ).getNativeBuffer ())
@@ -194,9 +193,9 @@ public NettyDataBuffer write(DataBuffer... buffers) {
194
193
return this ;
195
194
}
196
195
197
- private static boolean hasNettyDataBuffers (DataBuffer [] dataBuffers ) {
198
- for (DataBuffer dataBuffer : dataBuffers ) {
199
- if (!(dataBuffer instanceof NettyDataBuffer )) {
196
+ private static boolean hasNettyDataBuffers (DataBuffer [] buffers ) {
197
+ for (DataBuffer buffer : buffers ) {
198
+ if (!(buffer instanceof NettyDataBuffer )) {
200
199
return false ;
201
200
}
202
201
}
@@ -205,25 +204,25 @@ private static boolean hasNettyDataBuffers(DataBuffer[] dataBuffers) {
205
204
206
205
@ Override
207
206
public NettyDataBuffer write (ByteBuffer ... buffers ) {
208
- Assert . notNull (buffers , "'buffers' must not be null" );
209
-
210
- for ( ByteBuffer buffer : buffers ) {
211
- this . byteBuf . writeBytes ( buffer );
207
+ if (! ObjectUtils . isEmpty (buffers )) {
208
+ for ( ByteBuffer buffer : buffers ) {
209
+ this . byteBuf . writeBytes ( buffer );
210
+ }
212
211
}
213
212
return this ;
214
213
}
215
214
216
215
/**
217
- * Writes one or more Netty {@link ByteBuf}s to this buffer, starting at the current
218
- * writing position.
216
+ * Writes one or more Netty {@link ByteBuf}s to this buffer,
217
+ * starting at the current writing position.
219
218
* @param byteBufs the buffers to write into this buffer
220
219
* @return this buffer
221
220
*/
222
221
public NettyDataBuffer write (ByteBuf ... byteBufs ) {
223
- Assert . notNull (byteBufs , "'byteBufs' must not be null" );
224
-
225
- for ( ByteBuf byteBuf : byteBufs ) {
226
- this . byteBuf . writeBytes ( byteBuf );
222
+ if (! ObjectUtils . isEmpty (byteBufs )) {
223
+ for ( ByteBuf byteBuf : byteBufs ) {
224
+ this . byteBuf . writeBytes ( byteBuf );
225
+ }
227
226
}
228
227
return this ;
229
228
}
@@ -272,7 +271,7 @@ public boolean release() {
272
271
273
272
@ Override
274
273
public boolean equals (Object other ) {
275
- return (this == other || (other instanceof NettyDataBuffer &&
274
+ return (this == other || (other instanceof NettyDataBuffer &&
276
275
this .byteBuf .equals (((NettyDataBuffer ) other ).byteBuf )));
277
276
}
278
277
0 commit comments