/** * Creates a new big-endian direct buffer with reasonably small initial capacity, which * expands its capacity boundlessly on demand. */ public static ByteBuf directBuffer() { return ALLOC.directBuffer(); }
/** * Creates a new big-endian direct buffer with the specified {@code capacity}, which * expands its capacity boundlessly on demand. The new buffer's {@code readerIndex} and * {@code writerIndex} are {@code 0}. */ public static ByteBuf directBuffer(int initialCapacity) { return ALLOC.directBuffer(initialCapacity); }
/** * Creates a new big-endian direct buffer with the specified * {@code initialCapacity}, that may grow up to {@code maxCapacity}. * The new buffer's {@code readerIndex} and {@code writerIndex} are * {@code 0}. */ public static ByteBuf directBuffer(int initialCapacity, int maxCapacity) { return ALLOC.directBuffer(initialCapacity, maxCapacity); }
@Override public ByteBuf directBuffer(int initialCapacity, int maxCapacity) { return allocator.directBuffer(initialCapacity, maxCapacity); }
@Override public ByteBuf directBuffer() { return allocator.directBuffer(); }
@Override public ByteBuf directBuffer(int initialCapacity) { return allocator.directBuffer(initialCapacity); }
@Override public ByteBuf ioBuffer() { return POOLED.directBuffer(); }
/** * Creates a new big-endian direct buffer with the specified {@code capacity}, which * expands its capacity boundlessly on demand. The new buffer's {@code readerIndex} and * {@code writerIndex} are {@code 0}. */ public static ByteBuf directBuffer(int initialCapacity) { return ALLOC.directBuffer(initialCapacity); }
/** * Always prefer a direct buffer when it's pooled, so that we reduce the number of memory copies * in {@link OpenSslEngine}. */ private ByteBuf allocate(ChannelHandlerContext ctx, int capacity) { ByteBufAllocator alloc = ctx.alloc(); if (engineType.wantsDirectBuffer) { return alloc.directBuffer(capacity); } else { return alloc.buffer(capacity); } }
@Override public Buffer directBuffer(byte[] bytes) { ByteBuf buff = PartialPooledByteBufAllocator.UNPOOLED.directBuffer(bytes.length); buff.writeBytes(bytes); return new BufferImpl(buff); } }
private static ByteBuf newDirectBuffer0(Object holder, ByteBuf buf, ByteBufAllocator alloc, int capacity) { final ByteBuf directBuf = alloc.directBuffer(capacity); directBuf.writeBytes(buf, buf.readerIndex(), capacity); ReferenceCountUtil.safeRelease(holder); return directBuf; }
private static ByteBuf newDirectBuffer0(Object holder, ByteBuf buf, ByteBufAllocator alloc, int capacity) { final ByteBuf directBuf = alloc.directBuffer(capacity); directBuf.writeBytes(buf, buf.readerIndex(), capacity); ReferenceCountUtil.safeRelease(holder); return directBuf; }
@Override public ByteBuf copy(int index, int length) { ensureAccessible(); ByteBuffer src; try { src = (ByteBuffer) buffer.duplicate().clear().position(index).limit(index + length); } catch (IllegalArgumentException ignored) { throw new IndexOutOfBoundsException("Too many bytes to read - Need " + (index + length)); } return alloc().directBuffer(length, maxCapacity()).writeBytes(src); }
@Override public ByteBuf copy(int index, int length) { ensureAccessible(); ByteBuffer src; try { src = (ByteBuffer) buffer.duplicate().clear().position(index).limit(index + length); } catch (IllegalArgumentException ignored) { throw new IndexOutOfBoundsException("Too many bytes to read - Need " + (index + length)); } return alloc().directBuffer(length, maxCapacity()).writeBytes(src); }
@Override public ByteBuf copy(int index, int length) { ensureAccessible(); ByteBuffer src; try { src = (ByteBuffer) internalNioBuffer().clear().position(index).limit(index + length); } catch (IllegalArgumentException ignored) { throw new IndexOutOfBoundsException("Too many bytes to read - Need " + (index + length)); } ByteBuf dst = src.isDirect() ? alloc().directBuffer(length) : alloc().heapBuffer(length); dst.writeBytes(src); return dst; }
@Override public ByteBuf copy(int index, int length) { checkIndex(index, length); ByteBuf copy = alloc().directBuffer(length, maxCapacity()); copy.writeBytes(this, index, length); return copy; }
@Override public ByteBuf copy(int index, int length) { checkIndex(index, length); ByteBuf copy = alloc().directBuffer(length, maxCapacity()); copy.writeBytes(this, index, length); return copy; }
private ByteBuf allocBuffer(int capacity) { return direct ? alloc().directBuffer(capacity) : alloc().heapBuffer(capacity); }
static ByteBuf copy(AbstractByteBuf buf, long addr, int index, int length) { buf.checkIndex(index, length); ByteBuf copy = buf.alloc().directBuffer(length, buf.maxCapacity()); if (length != 0) { if (copy.hasMemoryAddress()) { PlatformDependent.copyMemory(addr, copy.memoryAddress(), length); copy.setIndex(0, length); } else { copy.writeBytes(buf, index, length); } } return copy; }
@Override public ByteBuf copy(int index, int length) { checkIndex(index, length); ByteBuf copy = alloc().directBuffer(length, maxCapacity()); if (length != 0) { if (copy.hasMemoryAddress()) { PlatformDependent.copyMemory(addr(index), copy.memoryAddress(), length); copy.setIndex(0, length); } else { copy.writeBytes(this, index, length); } } return copy; }