Class PooledByteBuf<T>

    • Method Detail

      • init

        void init​(PoolChunk<T> chunk,
                  java.nio.ByteBuffer nioBuffer,
                  long handle,
                  int offset,
                  int length,
                  int maxLength,
                  PoolArenasCache cache)
      • initUnpooled

        void initUnpooled​(PoolChunk<T> chunk,
                          int length)
      • init0

        private void init0​(PoolChunk<T> chunk,
                           java.nio.ByteBuffer nioBuffer,
                           long handle,
                           int offset,
                           int length,
                           int maxLength,
                           PoolArenasCache cache)
      • reuse

        final void reuse​(int maxCapacity)
        Method must be called before reuse this PooledByteBufAllocator
      • capacity

        public final int capacity()
        Description copied from class: ByteBuf
        Returns the number of bytes (octets) this buffer can contain.
        Specified by:
        capacity in class ByteBuf
      • capacity

        public final ByteBuf capacity​(int newCapacity)
        Description copied from class: ByteBuf
        Adjusts the capacity of this buffer. If the newCapacity is less than the current capacity, the content of this buffer is truncated. If the newCapacity is greater than the current capacity, the buffer is appended with unspecified data whose length is (newCapacity - currentCapacity).
        Specified by:
        capacity in class ByteBuf
      • order

        public final java.nio.ByteOrder order()
        Description copied from class: ByteBuf
        Returns the endianness of this buffer.
        Specified by:
        order in class ByteBuf
      • unwrap

        public final ByteBuf unwrap()
        Description copied from class: ByteBuf
        Return the underlying buffer instance if this buffer is a wrapper of another buffer.
        Specified by:
        unwrap in class ByteBuf
        Returns:
        null if this buffer is not a wrapper
      • retainedDuplicate

        public final ByteBuf retainedDuplicate()
        Description copied from class: ByteBuf
        Returns a retained buffer which shares the whole region of this buffer. Modifying the content of the returned buffer or this buffer affects each other's content while they maintain separate indexes and marks. This method is identical to buf.slice(0, buf.capacity()). This method does not modify readerIndex or writerIndex of this buffer.

        Note that this method returns a retained buffer unlike ByteBuf.slice(int, int). This method behaves similarly to duplicate().retain() except that this method may return a buffer implementation that produces less garbage.

        Overrides:
        retainedDuplicate in class AbstractByteBuf
      • retainedSlice

        public final ByteBuf retainedSlice()
        Description copied from class: ByteBuf
        Returns a retained slice of this buffer's readable bytes. Modifying the content of the returned buffer or this buffer affects each other's content while they maintain separate indexes and marks. This method is identical to buf.slice(buf.readerIndex(), buf.readableBytes()). This method does not modify readerIndex or writerIndex of this buffer.

        Note that this method returns a retained buffer unlike ByteBuf.slice(). This method behaves similarly to slice().retain() except that this method may return a buffer implementation that produces less garbage.

        Overrides:
        retainedSlice in class AbstractByteBuf
      • retainedSlice

        public final ByteBuf retainedSlice​(int index,
                                           int length)
        Description copied from class: ByteBuf
        Returns a retained slice of this buffer's sub-region. Modifying the content of the returned buffer or this buffer affects each other's content while they maintain separate indexes and marks. This method does not modify readerIndex or writerIndex of this buffer.

        Note that this method returns a retained buffer unlike ByteBuf.slice(int, int). This method behaves similarly to slice(...).retain() except that this method may return a buffer implementation that produces less garbage.

        Overrides:
        retainedSlice in class AbstractByteBuf
      • internalNioBuffer

        protected final java.nio.ByteBuffer internalNioBuffer()
      • newInternalNioBuffer

        protected abstract java.nio.ByteBuffer newInternalNioBuffer​(T memory)
      • idx

        protected final int idx​(int index)
      • _internalNioBuffer

        final java.nio.ByteBuffer _internalNioBuffer​(int index,
                                                     int length,
                                                     boolean duplicate)
      • duplicateInternalNioBuffer

        java.nio.ByteBuffer duplicateInternalNioBuffer​(int index,
                                                       int length)
      • internalNioBuffer

        public final java.nio.ByteBuffer internalNioBuffer​(int index,
                                                           int length)
        Description copied from class: ByteBuf
        Internal use only: Exposes the internal NIO buffer.
        Specified by:
        internalNioBuffer in class ByteBuf
      • nioBuffer

        public final java.nio.ByteBuffer nioBuffer​(int index,
                                                   int length)
        Description copied from class: ByteBuf
        Exposes this buffer's sub-region as an NIO ByteBuffer. The returned buffer either share or contains the copied content of this buffer, while changing the position and limit of the returned NIO buffer does not affect the indexes and marks of this buffer. This method does not modify readerIndex or writerIndex of this buffer. Please note that the returned NIO buffer will not see the changes of this buffer if this buffer is a dynamic buffer and it adjusted its capacity.
        Specified by:
        nioBuffer in class ByteBuf
        See Also:
        ByteBuf.nioBufferCount(), ByteBuf.nioBuffers(), ByteBuf.nioBuffers(int, int)
      • nioBuffers

        public final java.nio.ByteBuffer[] nioBuffers​(int index,
                                                      int length)
        Description copied from class: ByteBuf
        Exposes this buffer's bytes as an NIO ByteBuffer's for the specified index and length The returned buffer either share or contains the copied content of this buffer, while changing the position and limit of the returned NIO buffer does not affect the indexes and marks of this buffer. This method does not modify readerIndex or writerIndex of this buffer. Please note that the returned NIO buffer will not see the changes of this buffer if this buffer is a dynamic buffer and it adjusted its capacity.
        Specified by:
        nioBuffers in class ByteBuf
        See Also:
        ByteBuf.nioBufferCount(), ByteBuf.nioBuffer(), ByteBuf.nioBuffer(int, int)
      • isContiguous

        public final boolean isContiguous()
        Description copied from class: ByteBuf
        Returns true if this ByteBuf implementation is backed by a single memory region. Composite buffer implementations must return false even if they currently hold ≤ 1 components. For buffers that return true, it's guaranteed that a successful call to ByteBuf.discardReadBytes() will increase the value of ByteBuf.maxFastWritableBytes() by the current readerIndex.

        This method will return false by default, and a false return value does not necessarily mean that the implementation is composite or that it is not backed by a single memory region.

        Overrides:
        isContiguous in class ByteBuf
      • getBytes

        public final int getBytes​(int index,
                                  java.nio.channels.GatheringByteChannel out,
                                  int length)
                           throws java.io.IOException
        Description copied from class: ByteBuf
        Transfers this buffer's data to the specified channel starting at the specified absolute index. This method does not modify readerIndex or writerIndex of this buffer.
        Specified by:
        getBytes in class ByteBuf
        length - the maximum number of bytes to transfer
        Returns:
        the actual number of bytes written out to the specified channel
        Throws:
        java.io.IOException - if the specified channel threw an exception during I/O
      • readBytes

        public final int readBytes​(java.nio.channels.GatheringByteChannel out,
                                   int length)
                            throws java.io.IOException
        Description copied from class: ByteBuf
        Transfers this buffer's data to the specified stream starting at the current readerIndex.
        Overrides:
        readBytes in class AbstractByteBuf
        length - the maximum number of bytes to transfer
        Returns:
        the actual number of bytes written out to the specified channel
        Throws:
        java.io.IOException - if the specified channel threw an exception during I/O
      • getBytes

        public final int getBytes​(int index,
                                  java.nio.channels.FileChannel out,
                                  long position,
                                  int length)
                           throws java.io.IOException
        Description copied from class: ByteBuf
        Transfers this buffer's data starting at the specified absolute index to the specified channel starting at the given file position. This method does not modify readerIndex or writerIndex of this buffer. This method does not modify the channel's position.
        Specified by:
        getBytes in class ByteBuf
        position - the file position at which the transfer is to begin
        length - the maximum number of bytes to transfer
        Returns:
        the actual number of bytes written out to the specified channel
        Throws:
        java.io.IOException - if the specified channel threw an exception during I/O
      • readBytes

        public final int readBytes​(java.nio.channels.FileChannel out,
                                   long position,
                                   int length)
                            throws java.io.IOException
        Description copied from class: ByteBuf
        Transfers this buffer's data starting at the current readerIndex to the specified channel starting at the given file position. This method does not modify the channel's position.
        Overrides:
        readBytes in class AbstractByteBuf
        position - the file position at which the transfer is to begin
        length - the maximum number of bytes to transfer
        Returns:
        the actual number of bytes written out to the specified channel
        Throws:
        java.io.IOException - if the specified channel threw an exception during I/O
      • setBytes

        public final int setBytes​(int index,
                                  java.nio.channels.ScatteringByteChannel in,
                                  int length)
                           throws java.io.IOException
        Description copied from class: ByteBuf
        Transfers the content of the specified source channel to this buffer starting at the specified absolute index. This method does not modify readerIndex or writerIndex of this buffer.
        Specified by:
        setBytes in class ByteBuf
        length - the maximum number of bytes to transfer
        Returns:
        the actual number of bytes read in from the specified channel. -1 if the specified channel is closed or it reached EOF.
        Throws:
        java.io.IOException - if the specified channel threw an exception during I/O
      • setBytes

        public final int setBytes​(int index,
                                  java.nio.channels.FileChannel in,
                                  long position,
                                  int length)
                           throws java.io.IOException
        Description copied from class: ByteBuf
        Transfers the content of the specified source channel starting at the given file position to this buffer starting at the specified absolute index. This method does not modify readerIndex or writerIndex of this buffer. This method does not modify the channel's position.
        Specified by:
        setBytes in class ByteBuf
        position - the file position at which the transfer is to begin
        length - the maximum number of bytes to transfer
        Returns:
        the actual number of bytes read in from the specified channel. -1 if the specified channel is closed or it reached EOF.
        Throws:
        java.io.IOException - if the specified channel threw an exception during I/O