Class ForwardingReadableBuffer

  • All Implemented Interfaces:
    ReadableBuffer, java.io.Closeable, java.lang.AutoCloseable

    public abstract class ForwardingReadableBuffer
    extends java.lang.Object
    implements ReadableBuffer
    Base class for a wrapper around another ReadableBuffer.

    This class just passes every operation through to the underlying buffer. Subclasses may override methods to intercept certain operations.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private ReadableBuffer buf  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      byte[] array()
      Gets the backing array for this buffer.
      int arrayOffset()
      Gets the offset in the backing array of the current read position.
      boolean byteBufferSupported()
      Indicates whether or not ReadableBuffer.getByteBuffer() operation is supported for this buffer.
      void close()
      Closes this buffer and releases any resources.
      java.nio.ByteBuffer getByteBuffer()
      Gets a ByteBuffer that contains some bytes of the content next to be read, or null if this buffer has been exhausted.
      boolean hasArray()
      Indicates whether or not this buffer exposes a backing array.
      void mark()
      Marks the current position in this buffer.
      boolean markSupported()
      Indicates whether or not ReadableBuffer.mark() operation is supported for this buffer.
      int readableBytes()
      Gets the current number of readable bytes remaining in this buffer.
      void readBytes​(byte[] dest, int destOffset, int length)
      Reads length bytes from this buffer and writes them to the destination array.
      ReadableBuffer readBytes​(int length)
      Reads length bytes from this buffer and returns a new Buffer containing them.
      void readBytes​(java.io.OutputStream dest, int length)
      Reads length bytes from this buffer and writes them to the destination stream.
      void readBytes​(java.nio.ByteBuffer dest)
      Reads from this buffer until the destination's position reaches its limit, and increases the read position by the number of the transferred bytes.
      int readInt()
      Reads a 4-byte signed integer from this buffer using big-endian byte ordering.
      int readUnsignedByte()
      Reads the next unsigned byte from this buffer and increments the read position by 1.
      void reset()
      Repositions this buffer to the position at the time ReadableBuffer.mark() was last called on this buffer.
      void skipBytes​(int length)
      Increments the read position by the given length.
      java.lang.String toString()  
      void touch()
      Note that the current callsite has access to this buffer, or do nothing.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • ForwardingReadableBuffer

        protected ForwardingReadableBuffer​(ReadableBuffer buf)
        Constructor.
        Parameters:
        buf - the underlying buffer
    • Method Detail

      • readableBytes

        public int readableBytes()
        Description copied from interface: ReadableBuffer
        Gets the current number of readable bytes remaining in this buffer.
        Specified by:
        readableBytes in interface ReadableBuffer
      • readUnsignedByte

        public int readUnsignedByte()
        Description copied from interface: ReadableBuffer
        Reads the next unsigned byte from this buffer and increments the read position by 1.
        Specified by:
        readUnsignedByte in interface ReadableBuffer
      • readInt

        public int readInt()
        Description copied from interface: ReadableBuffer
        Reads a 4-byte signed integer from this buffer using big-endian byte ordering. Increments the read position by 4.
        Specified by:
        readInt in interface ReadableBuffer
      • skipBytes

        public void skipBytes​(int length)
        Description copied from interface: ReadableBuffer
        Increments the read position by the given length.
        Specified by:
        skipBytes in interface ReadableBuffer
      • readBytes

        public void readBytes​(byte[] dest,
                              int destOffset,
                              int length)
        Description copied from interface: ReadableBuffer
        Reads length bytes from this buffer and writes them to the destination array. Increments the read position by length.
        Specified by:
        readBytes in interface ReadableBuffer
        Parameters:
        dest - the destination array to receive the bytes.
        destOffset - the starting offset in the destination array.
        length - the number of bytes to be copied.
      • readBytes

        public void readBytes​(java.nio.ByteBuffer dest)
        Description copied from interface: ReadableBuffer
        Reads from this buffer until the destination's position reaches its limit, and increases the read position by the number of the transferred bytes.
        Specified by:
        readBytes in interface ReadableBuffer
        Parameters:
        dest - the destination buffer to receive the bytes.
      • readBytes

        public void readBytes​(java.io.OutputStream dest,
                              int length)
                       throws java.io.IOException
        Description copied from interface: ReadableBuffer
        Reads length bytes from this buffer and writes them to the destination stream. Increments the read position by length. If the required bytes are not readable, throws IndexOutOfBoundsException.
        Specified by:
        readBytes in interface ReadableBuffer
        Parameters:
        dest - the destination stream to receive the bytes.
        length - the number of bytes to be copied.
        Throws:
        java.io.IOException - thrown if any error was encountered while writing to the stream.
      • readBytes

        public ReadableBuffer readBytes​(int length)
        Description copied from interface: ReadableBuffer
        Reads length bytes from this buffer and returns a new Buffer containing them. Some implementations may return a Buffer sharing the backing memory with this buffer to prevent copying. However, that means that the returned buffer may keep the (possibly much larger) backing memory in use even after this buffer is closed.
        Specified by:
        readBytes in interface ReadableBuffer
        Parameters:
        length - the number of bytes to contain in returned Buffer.
      • hasArray

        public boolean hasArray()
        Description copied from interface: ReadableBuffer
        Indicates whether or not this buffer exposes a backing array.
        Specified by:
        hasArray in interface ReadableBuffer
      • touch

        public void touch()
        Description copied from interface: ReadableBuffer
        Note that the current callsite has access to this buffer, or do nothing. This is only useful when the buffer has leak detection and intrumentation to record usages before the buffer was leaked. That can make it much easier to track down where the buffer was leaked. If this isn't such a buffer, the method does nothing.
        Specified by:
        touch in interface ReadableBuffer
      • mark

        public void mark()
        Description copied from interface: ReadableBuffer
        Marks the current position in this buffer. A subsequent call to the ReadableBuffer.reset() method repositions this stream at the last marked position so that subsequent reads re-read the same bytes.
        Specified by:
        mark in interface ReadableBuffer
      • getByteBuffer

        @Nullable
        public java.nio.ByteBuffer getByteBuffer()
        Description copied from interface: ReadableBuffer
        Gets a ByteBuffer that contains some bytes of the content next to be read, or null if this buffer has been exhausted. The number of bytes contained in the returned buffer is implementation specific. The position of this buffer is unchanged after calling this method. The returned buffer's content should not be modified, but the position, limit, and mark may be changed. Operations for changing the position, limit, and mark of the returned buffer does not affect the position, limit, and mark of this buffer. Buffers returned by this method have independent position, limit and mark. This is an optional method, so callers should first check ReadableBuffer.byteBufferSupported().
        Specified by:
        getByteBuffer in interface ReadableBuffer
      • close

        public void close()
        Description copied from interface: ReadableBuffer
        Closes this buffer and releases any resources.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Specified by:
        close in interface ReadableBuffer
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object