Fix a bug where DefaultCompositeByteBuf.nioBuffers() fails when its component's nioBufferCount() is greater than 1
- Fixes #1267
This commit is contained in:
parent
9e890f0ab8
commit
8884e311f1
@ -1094,7 +1094,16 @@ public class DefaultCompositeByteBuf extends AbstractReferenceCountedByteBuf
|
||||
ByteBuf s = c.buf;
|
||||
int adjustment = c.offset;
|
||||
int localLength = Math.min(length, s.capacity() - (index - adjustment));
|
||||
buffers.add(s.nioBuffer(index - adjustment, localLength));
|
||||
switch (s.nioBufferCount()) {
|
||||
case 0:
|
||||
throw new UnsupportedOperationException();
|
||||
case 1:
|
||||
buffers.add(s.nioBuffer(index - adjustment, localLength));
|
||||
break;
|
||||
default:
|
||||
Collections.addAll(buffers, s.nioBuffers(index - adjustment, localLength));
|
||||
}
|
||||
|
||||
index += localLength;
|
||||
length -= localLength;
|
||||
i ++;
|
||||
|
@ -517,4 +517,20 @@ public abstract class AbstractCompositeByteBufTest extends
|
||||
c3.release(2);
|
||||
c2.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNestedLayout() {
|
||||
CompositeByteBuf buf = freeLater(compositeBuffer());
|
||||
buf.addComponent(
|
||||
compositeBuffer()
|
||||
.addComponent(wrappedBuffer(new byte[]{1, 2}))
|
||||
.addComponent(wrappedBuffer(new byte[]{3, 4})).slice(1, 2));
|
||||
|
||||
ByteBuffer[] nioBuffers = buf.nioBuffers(0, 2);
|
||||
assertThat(nioBuffers.length, is(2));
|
||||
assertThat(nioBuffers[0].remaining(), is(1));
|
||||
assertThat(nioBuffers[0].get(), is((byte) 2));
|
||||
assertThat(nioBuffers[1].remaining(), is(1));
|
||||
assertThat(nioBuffers[1].get(), is((byte) 3));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user