diff --git a/spring-web-reactive/src/main/java/org/springframework/core/io/buffer/DataBufferAllocator.java b/spring-web-reactive/src/main/java/org/springframework/core/io/buffer/DataBufferAllocator.java index e4586100f6..881de92684 100644 --- a/spring-web-reactive/src/main/java/org/springframework/core/io/buffer/DataBufferAllocator.java +++ b/spring-web-reactive/src/main/java/org/springframework/core/io/buffer/DataBufferAllocator.java @@ -42,20 +42,6 @@ public interface DataBufferAllocator { */ DataBuffer allocateBuffer(int initialCapacity); - /** - * Allocates a data buffer of the given initial capacity on the heap. - * @param initialCapacity the initial capacity of the buffer to allocate - * @return the allocated buffer - */ - DataBuffer allocateHeapBuffer(int initialCapacity); - - /** - * Allocates a direct data buffer of the given initial capacity. - * @param initialCapacity the initial capacity of the buffer to allocate - * @return the allocated buffer - */ - DataBuffer allocateDirectBuffer(int initialCapacity); - /** * Wraps the given {@link ByteBuffer} in a {@code DataBuffer}. * @param byteBuffer the NIO byte buffer to wrap 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 0f311978f5..fe320c995f 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 @@ -57,18 +57,9 @@ public class DefaultDataBufferAllocator implements DataBufferAllocator { @Override public DefaultDataBuffer allocateBuffer(int initialCapacity) { - return preferDirect ? allocateDirectBuffer(initialCapacity) : - allocateHeapBuffer(initialCapacity); - } - - @Override - public DefaultDataBuffer allocateHeapBuffer(int initialCapacity) { - return new DefaultDataBuffer(ByteBuffer.allocate(initialCapacity)); - } - - @Override - public DefaultDataBuffer allocateDirectBuffer(int initialCapacity) { - return new DefaultDataBuffer(ByteBuffer.allocateDirect(initialCapacity)); + return this.preferDirect ? + new DefaultDataBuffer(ByteBuffer.allocateDirect(initialCapacity)) : + new DefaultDataBuffer(ByteBuffer.allocate(initialCapacity)); } @Override 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 6eea0f3298..c77db97911 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 @@ -60,18 +60,6 @@ public class NettyDataBufferAllocator implements DataBufferAllocator { return new NettyDataBuffer(byteBuf); } - @Override - public NettyDataBuffer allocateHeapBuffer(int initialCapacity) { - ByteBuf byteBuf = this.byteBufAllocator.heapBuffer(initialCapacity); - return new NettyDataBuffer(byteBuf); - } - - @Override - public NettyDataBuffer allocateDirectBuffer(int initialCapacity) { - ByteBuf byteBuf = this.byteBufAllocator.directBuffer(initialCapacity); - return new NettyDataBuffer(byteBuf); - } - @Override public NettyDataBuffer wrap(ByteBuffer byteBuffer) { ByteBuf byteBuf = Unpooled.wrappedBuffer(byteBuffer); 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 8c104a6069..da27d1194b 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 @@ -37,28 +37,23 @@ import static org.junit.Assert.assertEquals; @RunWith(Parameterized.class) public class DataBufferTests { - @Parameterized.Parameter(0) + @Parameterized.Parameter public DataBufferAllocator allocator; - @Parameterized.Parameter(1) - public boolean direct; - - @Parameterized.Parameters(name = "{0} - direct: {1}") + @Parameterized.Parameters(name = "{0}") public static Object[][] buffers() { return new Object[][]{ - {new NettyDataBufferAllocator(new UnpooledByteBufAllocator(false)), true}, - {new NettyDataBufferAllocator(new UnpooledByteBufAllocator(false)), - false}, - {new NettyDataBufferAllocator(new PooledByteBufAllocator(false)), true}, - {new NettyDataBufferAllocator(new PooledByteBufAllocator(false)), false}, + {new NettyDataBufferAllocator(new UnpooledByteBufAllocator(true))}, + {new NettyDataBufferAllocator(new UnpooledByteBufAllocator(false))}, + {new NettyDataBufferAllocator(new PooledByteBufAllocator(true))}, + {new NettyDataBufferAllocator(new PooledByteBufAllocator(false))}, {new DefaultDataBufferAllocator(), true}, {new DefaultDataBufferAllocator(), false}}; } private DataBuffer createDataBuffer(int capacity) { - return direct ? allocator.allocateDirectBuffer(capacity) : - allocator.allocateHeapBuffer(capacity); + return allocator.allocateBuffer(capacity); } @Test @@ -183,8 +178,7 @@ public class DataBufferTests { } private ByteBuffer createByteBuffer(int capacity) { - return direct ? ByteBuffer.allocateDirect(capacity) : - ByteBuffer.allocate(capacity); + return ByteBuffer.allocate(capacity); } @Test