Incorporated misc. suggestions from the PR.
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DefaultDataBufferFactory";
|
||||
return "DefaultDataBufferFactory - preferDirect: " + this.preferDirect;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user