diff --git a/spring-web-reactive/src/main/java/org/springframework/core/io/buffer/DataBuffer.java b/spring-web-reactive/src/main/java/org/springframework/core/io/buffer/DataBuffer.java index 2af308228b3..49f5f557e05 100644 --- a/spring-web-reactive/src/main/java/org/springframework/core/io/buffer/DataBuffer.java +++ b/spring-web-reactive/src/main/java/org/springframework/core/io/buffer/DataBuffer.java @@ -23,9 +23,6 @@ import java.nio.ByteBuffer; /** * Basic abstraction over byte buffers. * - *

Mainly for internal use within the framework; consider Netty's - * {@link io.netty.buffer.ByteBuf} for a more comprehensive byte buffer. - * * @author Arjen Poutsma */ public interface DataBuffer { diff --git a/spring-web-reactive/src/main/java/org/springframework/core/io/buffer/DefaultDataBuffer.java b/spring-web-reactive/src/main/java/org/springframework/core/io/buffer/DefaultDataBuffer.java index 5795c2a74b9..4a1c73bb34d 100644 --- a/spring-web-reactive/src/main/java/org/springframework/core/io/buffer/DefaultDataBuffer.java +++ b/spring-web-reactive/src/main/java/org/springframework/core/io/buffer/DefaultDataBuffer.java @@ -28,12 +28,9 @@ import org.springframework.util.ObjectUtils; /** * Default implementation of the {@link DataBuffer} interface that uses a {@link - * ByteBuffer} internally, with separate read and write positions. Typically constructed + * ByteBuffer} internally, with separate read and write positions. Constructed * using the {@link DefaultDataBufferAllocator}. * - *

This class is rather limited; consider using Netty's - * {@link io.netty.buffer.ByteBuf} and {@link NettyDataBuffer} for a more comprehensive byte buffer. - * @author Arjen Poutsma * @see DefaultDataBufferAllocator */ diff --git a/spring-web-reactive/src/main/java/org/springframework/core/io/buffer/DefaultDataBufferAllocator.java b/spring-web-reactive/src/main/java/org/springframework/core/io/buffer/DefaultDataBufferAllocator.java index fe320c995fe..2c414e0de38 100644 --- a/spring-web-reactive/src/main/java/org/springframework/core/io/buffer/DefaultDataBufferAllocator.java +++ b/spring-web-reactive/src/main/java/org/springframework/core/io/buffer/DefaultDataBufferAllocator.java @@ -21,9 +21,6 @@ import java.nio.ByteBuffer; /** * Default implementation of the {@code DataBufferAllocator} interface. * - *

This class is rather limited; consider using Netty's - * {@link io.netty.buffer.ByteBuf} and {@link NettyDataBuffer} for a more comprehensive - * byte buffer. * @author Arjen Poutsma */ public class DefaultDataBufferAllocator implements DataBufferAllocator { @@ -70,7 +67,7 @@ public class DefaultDataBufferAllocator implements DataBufferAllocator { @Override public String toString() { - return "DefaultDataBufferFactory"; + return "DefaultDataBufferFactory - preferDirect: " + this.preferDirect; } } diff --git a/spring-web-reactive/src/main/java/org/springframework/core/io/buffer/NettyDataBuffer.java b/spring-web-reactive/src/main/java/org/springframework/core/io/buffer/NettyDataBuffer.java index f2a4bcf841a..0c03db43e6a 100644 --- a/spring-web-reactive/src/main/java/org/springframework/core/io/buffer/NettyDataBuffer.java +++ b/spring-web-reactive/src/main/java/org/springframework/core/io/buffer/NettyDataBuffer.java @@ -107,12 +107,9 @@ public class NettyDataBuffer implements DataBuffer { public NettyDataBuffer write(DataBuffer... buffers) { if (!ObjectUtils.isEmpty(buffers)) { if (buffers[0] instanceof NettyDataBuffer) { - NettyDataBuffer[] copy = - Arrays.copyOf(buffers, buffers.length, NettyDataBuffer[].class); - - ByteBuf[] nativeBuffers = - Arrays.stream(copy).map(NettyDataBuffer::getNativeBuffer) - .toArray(ByteBuf[]::new); + ByteBuf[] nativeBuffers = Arrays.stream(buffers) + .map(b -> ((NettyDataBuffer) b).getNativeBuffer()) + .toArray(ByteBuf[]::new); write(nativeBuffers); } @@ -149,7 +146,7 @@ public class NettyDataBuffer implements DataBuffer { new CompositeByteBuf(this.byteBuf.alloc(), this.byteBuf.isDirect(), byteBufs.length + 1); composite.addComponent(this.byteBuf); - Arrays.stream(byteBufs).forEach(composite::addComponent); + composite.addComponents(byteBufs); int writerIndex = this.byteBuf.readableBytes() + Arrays.stream(byteBufs).mapToInt(ByteBuf::readableBytes).sum(); diff --git a/spring-web-reactive/src/main/java/org/springframework/core/io/buffer/NettyDataBufferAllocator.java b/spring-web-reactive/src/main/java/org/springframework/core/io/buffer/NettyDataBufferAllocator.java index c77db979113..092e33518b8 100644 --- a/spring-web-reactive/src/main/java/org/springframework/core/io/buffer/NettyDataBufferAllocator.java +++ b/spring-web-reactive/src/main/java/org/springframework/core/io/buffer/NettyDataBufferAllocator.java @@ -25,7 +25,7 @@ import io.netty.buffer.Unpooled; import org.springframework.util.Assert; /** - * Implemtation of the {@code DataBufferAllocator} interface based on a Netty + * Implementation of the {@code DataBufferAllocator} interface based on a Netty * {@link ByteBufAllocator}. * * @author Arjen Poutsma diff --git a/spring-web-reactive/src/test/java/org/springframework/core/io/buffer/DataBufferTests.java b/spring-web-reactive/src/test/java/org/springframework/core/io/buffer/DataBufferTests.java index da27d1194b9..8169f5e142b 100644 --- a/spring-web-reactive/src/test/java/org/springframework/core/io/buffer/DataBufferTests.java +++ b/spring-web-reactive/src/test/java/org/springframework/core/io/buffer/DataBufferTests.java @@ -48,8 +48,8 @@ public class DataBufferTests { {new NettyDataBufferAllocator(new UnpooledByteBufAllocator(false))}, {new NettyDataBufferAllocator(new PooledByteBufAllocator(true))}, {new NettyDataBufferAllocator(new PooledByteBufAllocator(false))}, - {new DefaultDataBufferAllocator(), true}, - {new DefaultDataBufferAllocator(), false}}; + {new DefaultDataBufferAllocator(true)}, + {new DefaultDataBufferAllocator(false)}}; } private DataBuffer createDataBuffer(int capacity) {