CompositeByteBuf.isDirect() should return true if its only backed by direct buffers

This commit is contained in:
Norman Maurer 2013-09-26 07:04:53 +02:00
parent a74149e984
commit 2b9a07cac9
2 changed files with 25 additions and 3 deletions

View File

@ -430,10 +430,16 @@ public class CompositeByteBuf extends AbstractReferenceCountedByteBuf {
@Override
public boolean isDirect() {
if (components.size() == 1) {
return components.get(0).buf.isDirect();
int size = components.size();
if (size == 0) {
return false;
}
return false;
for (int i = 0; i < size; i++) {
if (!components.get(i).buf.isDirect()) {
return false;
}
}
return true;
}
@Override

View File

@ -776,4 +776,20 @@ public abstract class AbstractCompositeByteBufTest extends AbstractByteBufTest {
public void testInternalNioBuffer() {
// ignore
}
@Test
public void testisDirectMultipleBufs() {
CompositeByteBuf buf = freeLater(compositeBuffer());
assertFalse(buf.isDirect());
buf.addComponent(directBuffer().writeByte(1));
assertTrue(buf.isDirect());
buf.addComponent(directBuffer().writeByte(1));
assertTrue(buf.isDirect());
buf.addComponent(buffer().writeByte(1));
assertFalse(buf.isDirect());
}
}