Fix nioBuffer implementation for CompositeByteBuf
This commit is contained in:
parent
c0b9ef9386
commit
335f3807a5
@ -1122,7 +1122,7 @@ public class CompositeByteBuf extends AbstractReferenceCountedByteBuf {
|
|||||||
|
|
||||||
//noinspection ForLoopReplaceableByForEach
|
//noinspection ForLoopReplaceableByForEach
|
||||||
for (int i = 0; i < buffers.length; i++) {
|
for (int i = 0; i < buffers.length; i++) {
|
||||||
merged.put(buffers[0]);
|
merged.put(buffers[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
merged.flip();
|
merged.flip();
|
||||||
|
@ -176,6 +176,27 @@ public abstract class AbstractCompositeByteBufTest extends AbstractByteBufTest {
|
|||||||
assertEquals(0, buf.arrayOffset());
|
assertEquals(0, buf.arrayOffset());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCompositeToSingleBuffer() {
|
||||||
|
CompositeByteBuf buf = compositeBuffer(3);
|
||||||
|
|
||||||
|
buf.addComponent(wrappedBuffer(new byte[] {1, 2, 3}));
|
||||||
|
assertEquals(1, buf.numComponents());
|
||||||
|
|
||||||
|
buf.addComponent(wrappedBuffer(new byte[] {4}));
|
||||||
|
assertEquals(2, buf.numComponents());
|
||||||
|
|
||||||
|
buf.addComponent(wrappedBuffer(new byte[] {5, 6}));
|
||||||
|
assertEquals(3, buf.numComponents());
|
||||||
|
|
||||||
|
// NOTE: hard-coding 6 here, since it seems like addComponent doesn't bump the writer index.
|
||||||
|
// I'm unsure as to whether or not this is correct behavior
|
||||||
|
ByteBuffer nioBuffer = buf.nioBuffer(0, 6);
|
||||||
|
byte[] bytes = nioBuffer.array();
|
||||||
|
assertEquals(6, bytes.length);
|
||||||
|
assertArrayEquals(new byte[] {1, 2, 3, 4, 5, 6}, bytes);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFullConsolidation() {
|
public void testFullConsolidation() {
|
||||||
CompositeByteBuf buf = freeLater(compositeBuffer(Integer.MAX_VALUE));
|
CompositeByteBuf buf = freeLater(compositeBuffer(Integer.MAX_VALUE));
|
||||||
|
Loading…
Reference in New Issue
Block a user