Browse Source

Incorporated misc. suggestions from the PR.

pull/1111/head
Arjen Poutsma 10 years ago
parent
commit
c84ef6cbf3
  1. 3
      spring-web-reactive/src/main/java/org/springframework/core/io/buffer/DataBuffer.java
  2. 5
      spring-web-reactive/src/main/java/org/springframework/core/io/buffer/DefaultDataBuffer.java
  3. 5
      spring-web-reactive/src/main/java/org/springframework/core/io/buffer/DefaultDataBufferAllocator.java
  4. 11
      spring-web-reactive/src/main/java/org/springframework/core/io/buffer/NettyDataBuffer.java
  5. 2
      spring-web-reactive/src/main/java/org/springframework/core/io/buffer/NettyDataBufferAllocator.java
  6. 4
      spring-web-reactive/src/test/java/org/springframework/core/io/buffer/DataBufferTests.java

3
spring-web-reactive/src/main/java/org/springframework/core/io/buffer/DataBuffer.java

@ -23,9 +23,6 @@ import java.nio.ByteBuffer; @@ -23,9 +23,6 @@ import java.nio.ByteBuffer;
/**
* Basic abstraction over byte buffers.
*
* <p>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 {

5
spring-web-reactive/src/main/java/org/springframework/core/io/buffer/DefaultDataBuffer.java

@ -28,12 +28,9 @@ import org.springframework.util.ObjectUtils; @@ -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}.
*
* <p>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
*/

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

@ -21,9 +21,6 @@ import java.nio.ByteBuffer; @@ -21,9 +21,6 @@ import java.nio.ByteBuffer;
/**
* Default implementation of the {@code DataBufferAllocator} interface.
*
* <p>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 { @@ -70,7 +67,7 @@ public class DefaultDataBufferAllocator implements DataBufferAllocator {
@Override
public String toString() {
return "DefaultDataBufferFactory";
return "DefaultDataBufferFactory - preferDirect: " + this.preferDirect;
}
}

11
spring-web-reactive/src/main/java/org/springframework/core/io/buffer/NettyDataBuffer.java

@ -107,12 +107,9 @@ public class NettyDataBuffer implements DataBuffer { @@ -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 { @@ -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();

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

@ -25,7 +25,7 @@ import io.netty.buffer.Unpooled; @@ -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

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

@ -48,8 +48,8 @@ public class DataBufferTests { @@ -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) {

Loading…
Cancel
Save