Class NioDataBuffer

  • All Implemented Interfaces:
    DataBuffer

    public class NioDataBuffer
    extends java.lang.Object
    implements DataBuffer
    A DataBuffer with the underlying data being a ByteBuffer. If the backing ByteBuffer is a direct ByteBuffer, release() should only be called when all references to the object are finished with it. For this reason, it is not recommended to share objects of this class unless reference counting is implemented by the users of this class.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.nio.ByteBuffer mBuffer  
      protected long mLength  
    • Constructor Summary

      Constructors 
      Constructor Description
      NioDataBuffer​(java.nio.ByteBuffer buffer, long length)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      long getLength()
      Returns the length of the data.
      java.lang.Object getNettyOutput()
      Returns an object for writing to a netty channel.
      java.nio.ByteBuffer getReadOnlyByteBuffer()
      Returns a ByteBuffer for read-only access to the data.
      int readableBytes()  
      void readBytes​(byte[] dst, int dstIndex, int length)
      Transfers this buffer's data to the specified destination starting at the current readerIndex and increases the readerIndex by the number of the transferred bytes (= length).
      void readBytes​(java.io.OutputStream outputStream, int length)
      Transfers this buffer's data to the given stream.
      void readBytes​(java.nio.ByteBuffer outputBuf)
      Transfers this buffer's data to the given ByteBuffer.
      void release()
      Releases the underlying buffer of this DataBuffer if no longer needed.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • mBuffer

        protected final java.nio.ByteBuffer mBuffer
      • mLength

        protected final long mLength
    • Constructor Detail

      • NioDataBuffer

        public NioDataBuffer​(java.nio.ByteBuffer buffer,
                             long length)
        Parameters:
        buffer - The ByteBuffer representing the data
        length - The length of the ByteBuffer
    • Method Detail

      • getNettyOutput

        public java.lang.Object getNettyOutput()
        Description copied from interface: DataBuffer
        Returns an object for writing to a netty channel.
        Specified by:
        getNettyOutput in interface DataBuffer
        Returns:
        the object to output to Netty. Must be ByteBuf or FileRegion
      • getLength

        public long getLength()
        Description copied from interface: DataBuffer
        Returns the length of the data.
        Specified by:
        getLength in interface DataBuffer
        Returns:
        the length of the data in bytes
      • getReadOnlyByteBuffer

        public java.nio.ByteBuffer getReadOnlyByteBuffer()
        Description copied from interface: DataBuffer
        Returns a ByteBuffer for read-only access to the data.
        Specified by:
        getReadOnlyByteBuffer in interface DataBuffer
        Returns:
        a read-only ByteBuffer representing the data
      • readBytes

        public void readBytes​(byte[] dst,
                              int dstIndex,
                              int length)
        Description copied from interface: DataBuffer
        Transfers this buffer's data to the specified destination starting at the current readerIndex and increases the readerIndex by the number of the transferred bytes (= length).
        Specified by:
        readBytes in interface DataBuffer
        Parameters:
        dst - the destination
        dstIndex - the first index of the destination
        length - the number of bytes to transfer
      • readBytes

        public void readBytes​(java.io.OutputStream outputStream,
                              int length)
                       throws java.io.IOException
        Description copied from interface: DataBuffer
        Transfers this buffer's data to the given stream.
        Specified by:
        readBytes in interface DataBuffer
        Parameters:
        outputStream - the stream to transfer data to
        length - length of the data to be transferred
        Throws:
        java.io.IOException
      • readBytes

        public void readBytes​(java.nio.ByteBuffer outputBuf)
        Description copied from interface: DataBuffer
        Transfers this buffer's data to the given ByteBuffer.
        Specified by:
        readBytes in interface DataBuffer
        Parameters:
        outputBuf - the buffer to transfer data to
      • readableBytes

        public int readableBytes()
        Specified by:
        readableBytes in interface DataBuffer
        Returns:
        the number of readable bytes remaining
      • release

        public void release()
        Description copied from interface: DataBuffer
        Releases the underlying buffer of this DataBuffer if no longer needed.
        Specified by:
        release in interface DataBuffer