/** * Creates a new direct buffer with the specified {@code endianness} and {@code capacity}. The new * buffer's {@code readerIndex} and {@code writerIndex} are {@code 0}. */ public static ChannelBuffer directBuffer(ByteOrder endianness, int capacity) { if (endianness == null) { throw new NullPointerException("endianness"); } if (capacity == 0) { return EMPTY_BUFFER; } ChannelBuffer buffer = new ByteBufferBackedChannelBuffer(ByteBuffer.allocateDirect(capacity).order(endianness)); buffer.clear(); return buffer; }
public ChannelBuffer getBuffer(ByteOrder order, int capacity) { if (order == null) { throw new NullPointerException("order"); } if (capacity < 0) { throw new IllegalArgumentException("capacity: " + capacity); } if (capacity == 0) { return ChannelBuffers.EMPTY_BUFFER; } if (capacity >= preallocatedBufferCapacity) { return ChannelBuffers.directBuffer(order, capacity); } ChannelBuffer slice; if (order == ByteOrder.BIG_ENDIAN) { slice = allocateBigEndianBuffer(capacity); } else { slice = allocateLittleEndianBuffer(capacity); } slice.clear(); return slice; }