From 4cb023f190d5739b0c19077d309e3d3ae24e482d Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Tue, 5 Mar 2013 17:59:31 +0900 Subject: [PATCH] Add more variants of ByteBufAllocator.ioBuffer() / Update Javadoc --- .../buffer/AbstractByteBufAllocator.java | 16 +++++++++++++++ .../io/netty/buffer/ByteBufAllocator.java | 20 ++++++++++++++----- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/buffer/src/main/java/io/netty/buffer/AbstractByteBufAllocator.java b/buffer/src/main/java/io/netty/buffer/AbstractByteBufAllocator.java index 5da1e2b809..a8855e2373 100644 --- a/buffer/src/main/java/io/netty/buffer/AbstractByteBufAllocator.java +++ b/buffer/src/main/java/io/netty/buffer/AbstractByteBufAllocator.java @@ -76,6 +76,22 @@ public abstract class AbstractByteBufAllocator implements ByteBufAllocator { return heapBuffer(0); } + @Override + public ByteBuf ioBuffer(int initialCapacity) { + if (PlatformDependent.hasUnsafe()) { + return directBuffer(initialCapacity); + } + return heapBuffer(initialCapacity); + } + + @Override + public ByteBuf ioBuffer(int initialCapacity, int maxCapacity) { + if (PlatformDependent.hasUnsafe()) { + return directBuffer(initialCapacity, maxCapacity); + } + return heapBuffer(initialCapacity, maxCapacity); + } + @Override public ByteBuf heapBuffer() { return heapBuffer(256, Integer.MAX_VALUE); diff --git a/buffer/src/main/java/io/netty/buffer/ByteBufAllocator.java b/buffer/src/main/java/io/netty/buffer/ByteBufAllocator.java index 285d22c551..ac5a6a99e2 100644 --- a/buffer/src/main/java/io/netty/buffer/ByteBufAllocator.java +++ b/buffer/src/main/java/io/netty/buffer/ByteBufAllocator.java @@ -40,6 +40,21 @@ public interface ByteBufAllocator { */ ByteBuf buffer(int initialCapacity, int maxCapacity); + /** + * Allocate a {@link ByteBuf} whose initial capacity is 0, preferably a direct buffer which is suitable for I/O. + */ + ByteBuf ioBuffer(); + + /** + * Allocate a {@link ByteBuf}, preferably a direct buffer which is suitable for I/O. + */ + ByteBuf ioBuffer(int initialCapacity); + + /** + * Allocate a {@link ByteBuf}, preferably a direct buffer which is suitable for I/O. + */ + ByteBuf ioBuffer(int initialCapacity, int maxCapacity); + /** * Allocate a heap {@link ByteBuf}. */ @@ -72,11 +87,6 @@ public interface ByteBufAllocator { */ ByteBuf directBuffer(int initialCapacity, int maxCapacity); - /** - * Allocate a {@link ByteBuf} which is used for reading data in from the actual transport. - */ - ByteBuf ioBuffer(); - /** * Allocate a {@link CompositeByteBuf}. * If it is a direct or heap buffer depends on the actual implementation.