Class NettyBufferPool

    • Constructor Detail

      • NettyBufferPool

        public NettyBufferPool​(io.netty.handler.codec.http.FullHttpResponse response)
        Instantiate.
        Parameters:
        response - FullHttpResponse.
    • Method Detail

      • getUnpooledStreamBuffer

        public StreamBuffer<io.netty.buffer.ByteBuf> getUnpooledStreamBuffer​(java.nio.ByteBuffer buffer)
        Description copied from interface: StreamBufferPool

        Obtains an StreamBuffer that is not pooled. This is for ByteBuffer instances that are managed outside the BufferPool.

        Typical use is to create StreamBuffer for some read-only cached content within a ByteBuffer.

        Specified by:
        getUnpooledStreamBuffer in interface StreamBufferPool<io.netty.buffer.ByteBuf>
        Parameters:
        buffer - ByteBuffer.
        Returns:
        StreamBuffer for the unpooled ByteBuffer.
      • getFileStreamBuffer

        public StreamBuffer<io.netty.buffer.ByteBuf> getFileStreamBuffer​(java.nio.channels.FileChannel file,
                                                                         long position,
                                                                         long count,
                                                                         FileCompleteCallback callback)
                                                                  throws java.io.IOException
        Description copied from interface: StreamBufferPool

        Obtains a StreamBuffer for the FileChannel content.

        This enables efficient writing (ie DMA) of FileChannel content.

        To write the entire FileChannel contents, invoke write(file, 0, -1).

        Note that the underlying implementation will need to support FileChannel efficiencies.

        Specified by:
        getFileStreamBuffer in interface StreamBufferPool<io.netty.buffer.ByteBuf>
        Parameters:
        file - FileChannel.
        position - Position within the FileChannel to start writing content. Must be non-negative number.
        count - Count of bytes to write from the FileChannel. A negative value (typically -1) indicates to write the remaining FileChannel content from the position.
        callback - Optional FileCompleteCallback. May be null.
        Returns:
        StreamBuffer for the FileChannel.
        Throws:
        java.io.IOException - If fails to create the StreamBuffer for the FileChannel. Typically, this is because the underlying implementation does not support DMA and copies the data from the FileChannel.
      • close

        public void close()
        Description copied from interface: StreamBufferPool
        Closes pool releasing all StreamBuffer instances.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface StreamBufferPool<io.netty.buffer.ByteBuf>
      • write

        public boolean write​(byte datum)
        Description copied from class: StreamBuffer
        Writes a byte to the pooled buffer.
        Specified by:
        write in class StreamBuffer<io.netty.buffer.ByteBuf>
        Parameters:
        datum - Byte value.
        Returns:
        true if written value to buffer. false indicates the pooled buffer is full.
      • write

        public int write​(byte[] data,
                         int offset,
                         int length)
        Description copied from class: StreamBuffer
        Writes the data to the pooled buffer.
        Specified by:
        write in class StreamBuffer<io.netty.buffer.ByteBuf>
        Parameters:
        data - Data to write to the pooled buffer.
        offset - Offset within the data to write the data.
        length - Length of data to write the data.
        Returns:
        Number of bytes written.