@Override public final ByteBuf capacity(int newCapacity) { checkNewCapacity(newCapacity); if (newCapacity > maxLength - 16) { length = newCapacity; setIndex(Math.min(readerIndex(), newCapacity), Math.min(writerIndex(), newCapacity)); return this; setIndex(Math.min(readerIndex(), newCapacity), Math.min(writerIndex(), newCapacity)); return this;
/** * Method must be called before reuse this {@link PooledByteBufAllocator} */ final void reuse(int maxCapacity) { maxCapacity(maxCapacity); setRefCnt(1); setIndex0(0, 0); discardMarks(); }
@Override void init(PoolChunk<ByteBuffer> chunk, ByteBuffer nioBuffer, long handle, int offset, int length, int maxLength, PoolThreadCache cache) { super.init(chunk, nioBuffer, handle, offset, length, maxLength, cache); initMemoryAddress(); }
@Override public final ByteBuf retainedSlice() { final int index = readerIndex(); return retainedSlice(index, writerIndex() - index); }
@Override public final ByteBuf retainedDuplicate() { return PooledDuplicatedByteBuf.newInstance(this, this, readerIndex(), writerIndex()); }
void reallocate(PooledByteBuf<T> buf, int newCapacity, boolean freeOldMemory) { if (newCapacity < 0 || newCapacity > buf.maxCapacity()) { throw new IllegalArgumentException("newCapacity: " + newCapacity); int oldOffset = buf.offset; int oldMaxLength = buf.maxLength; int readerIndex = buf.readerIndex(); int writerIndex = buf.writerIndex(); buf.setIndex(readerIndex, writerIndex);
@Override void initUnpooled(PoolChunk<ByteBuffer> chunk, int length) { super.initUnpooled(chunk, length); initMemoryAddress(); }
void init(PoolChunk<T> chunk, ByteBuffer nioBuffer, long handle, int offset, int length, int maxLength, PoolThreadCache cache) { init0(chunk, nioBuffer, handle, offset, length, maxLength, cache); }
@Override protected final void deallocate() { if (handle >= 0) { final long handle = this.handle; this.handle = -1; memory = null; chunk.arena.free(chunk, tmpNioBuf, handle, maxLength, cache); tmpNioBuf = null; chunk = null; recycle(); } }
protected final ByteBuffer internalNioBuffer() { ByteBuffer tmpNioBuf = this.tmpNioBuf; if (tmpNioBuf == null) { this.tmpNioBuf = tmpNioBuf = newInternalNioBuffer(memory); } return tmpNioBuf; }
@Override protected SwappedByteBuf newSwappedByteBuf() { if (PlatformDependent.isUnaligned()) { // Only use if unaligned access is supported otherwise there is no gain. return new UnsafeDirectSwappedByteBuf(this); } return super.newSwappedByteBuf(); }
void reallocate(PooledByteBuf<T> buf, int newCapacity, boolean freeOldMemory) { if (newCapacity < 0 || newCapacity > buf.maxCapacity()) { throw new IllegalArgumentException("newCapacity: " + newCapacity); int oldOffset = buf.offset; int oldMaxLength = buf.maxLength; int readerIndex = buf.readerIndex(); int writerIndex = buf.writerIndex(); buf.setIndex(readerIndex, writerIndex);
@Override public final ByteBuf retainedSlice() { final int index = readerIndex(); return retainedSlice(index, writerIndex() - index); }
@Override public final ByteBuf retainedDuplicate() { return PooledDuplicatedByteBuf.newInstance(this, this, readerIndex(), writerIndex()); }
@Override void initUnpooled(PoolChunk<ByteBuffer> chunk, int length) { super.initUnpooled(chunk, length); initMemoryAddress(); }
void initUnpooled(PoolChunk<T> chunk, int length) { init0(chunk, null, 0, chunk.offset, length, length, null); }
@Override protected final void deallocate() { if (handle >= 0) { final long handle = this.handle; this.handle = -1; memory = null; chunk.arena.free(chunk, tmpNioBuf, handle, maxLength, cache); tmpNioBuf = null; chunk = null; recycle(); } }
protected final ByteBuffer internalNioBuffer() { ByteBuffer tmpNioBuf = this.tmpNioBuf; if (tmpNioBuf == null) { this.tmpNioBuf = tmpNioBuf = newInternalNioBuffer(memory); } return tmpNioBuf; }
@Override protected SwappedByteBuf newSwappedByteBuf() { if (PlatformDependent.isUnaligned()) { // Only use if unaligned access is supported otherwise there is no gain. return new UnsafeDirectSwappedByteBuf(this); } return super.newSwappedByteBuf(); }
/** * Method must be called before reuse this {@link PooledByteBufAllocator} */ final void reuse(int maxCapacity) { maxCapacity(maxCapacity); setRefCnt(1); setIndex0(0, 0); discardMarks(); }