Browse Source

Removed DataBufferAllocator.allocateHeapBuffer and allocateDirectBuffer in favor of allocateBuffer.

pull/1111/head
Arjen Poutsma 9 years ago
parent
commit
66c424daf9
  1. 14
      spring-web-reactive/src/main/java/org/springframework/core/io/buffer/DataBufferAllocator.java
  2. 15
      spring-web-reactive/src/main/java/org/springframework/core/io/buffer/DefaultDataBufferAllocator.java
  3. 12
      spring-web-reactive/src/main/java/org/springframework/core/io/buffer/NettyDataBufferAllocator.java
  4. 22
      spring-web-reactive/src/test/java/org/springframework/core/io/buffer/DataBufferTests.java

14
spring-web-reactive/src/main/java/org/springframework/core/io/buffer/DataBufferAllocator.java

@ -42,20 +42,6 @@ public interface DataBufferAllocator { @@ -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

15
spring-web-reactive/src/main/java/org/springframework/core/io/buffer/DefaultDataBufferAllocator.java

@ -57,18 +57,9 @@ public class DefaultDataBufferAllocator implements DataBufferAllocator { @@ -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

12
spring-web-reactive/src/main/java/org/springframework/core/io/buffer/NettyDataBufferAllocator.java

@ -60,18 +60,6 @@ public class NettyDataBufferAllocator implements DataBufferAllocator { @@ -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);

22
spring-web-reactive/src/test/java/org/springframework/core/io/buffer/DataBufferTests.java

@ -37,28 +37,23 @@ import static org.junit.Assert.assertEquals; @@ -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 { @@ -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

Loading…
Cancel
Save