Fix nioBuffer implementation for CompositeByteBuf
This commit is contained in:
parent
3957ee32bb
commit
f1d4f813ed
@ -1122,7 +1122,7 @@ public class CompositeByteBuf extends AbstractReferenceCountedByteBuf {
|
||||
|
||||
//noinspection ForLoopReplaceableByForEach
|
||||
for (int i = 0; i < buffers.length; i++) {
|
||||
merged.put(buffers[0]);
|
||||
merged.put(buffers[i]);
|
||||
}
|
||||
|
||||
merged.flip();
|
||||
|
@ -176,6 +176,27 @@ public abstract class AbstractCompositeByteBufTest extends AbstractByteBufTest {
|
||||
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
|
||||
public void testFullConsolidation() {
|
||||
CompositeByteBuf buf = freeLater(compositeBuffer(Integer.MAX_VALUE));
|
||||
|
Loading…
Reference in New Issue
Block a user