From fc805a07877370ab1dc22f6d70e3e01a1b1bbe78 Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Thu, 26 Sep 2013 07:04:53 +0200 Subject: [PATCH] CompositeByteBuf.isDirect() should return true if its only backed by direct buffers --- .../java/io/netty/buffer/CompositeByteBuf.java | 12 +++++++++--- .../buffer/AbstractCompositeByteBufTest.java | 16 ++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/buffer/src/main/java/io/netty/buffer/CompositeByteBuf.java b/buffer/src/main/java/io/netty/buffer/CompositeByteBuf.java index 37d37ca435..007b944bea 100644 --- a/buffer/src/main/java/io/netty/buffer/CompositeByteBuf.java +++ b/buffer/src/main/java/io/netty/buffer/CompositeByteBuf.java @@ -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 diff --git a/buffer/src/test/java/io/netty/buffer/AbstractCompositeByteBufTest.java b/buffer/src/test/java/io/netty/buffer/AbstractCompositeByteBufTest.java index a03f201113..a3523ed72a 100644 --- a/buffer/src/test/java/io/netty/buffer/AbstractCompositeByteBufTest.java +++ b/buffer/src/test/java/io/netty/buffer/AbstractCompositeByteBufTest.java @@ -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()); + + } }