Class ReadableBuffers.ByteReadableBufferWrapper

java.lang.Object
io.grpc.internal.AbstractReadableBuffer
io.grpc.internal.ReadableBuffers.ByteReadableBufferWrapper
All Implemented Interfaces:
ReadableBuffer, Closeable, AutoCloseable
Enclosing class:
ReadableBuffers

private static class ReadableBuffers.ByteReadableBufferWrapper extends AbstractReadableBuffer
A ReadableBuffer that is backed by a ByteBuffer.
  • Field Details

  • Constructor Details

    • ByteReadableBufferWrapper

      ByteReadableBufferWrapper(ByteBuffer bytes)
  • Method Details

    • readableBytes

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

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

      public void skipBytes(int length)
      Description copied from interface: ReadableBuffer
      Increments the read position by the given length.
    • 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.
      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(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.
      Parameters:
      dest - the destination buffer to receive the bytes.
    • readBytes

      public void readBytes(OutputStream dest, int length) throws 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.
      Parameters:
      dest - the destination stream to receive the bytes.
      length - the number of bytes to be copied.
      Throws:
      IOException - thrown if any error was encountered while writing to the stream.
    • readBytes

      public ReadableBuffers.ByteReadableBufferWrapper 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.
      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
      Overrides:
      hasArray in class AbstractReadableBuffer
    • array

      public byte[] array()
      Description copied from interface: ReadableBuffer
      Gets the backing array for this buffer. This is an optional method, so callers should first check ReadableBuffer.hasArray().
      Specified by:
      array in interface ReadableBuffer
      Overrides:
      array in class AbstractReadableBuffer
    • arrayOffset

      public int arrayOffset()
      Description copied from interface: ReadableBuffer
      Gets the offset in the backing array of the current read position. This is an optional method, so callers should first check ReadableBuffer.hasArray()
      Specified by:
      arrayOffset in interface ReadableBuffer
      Overrides:
      arrayOffset in class AbstractReadableBuffer
    • markSupported

      public boolean markSupported()
      Description copied from interface: ReadableBuffer
      Indicates whether or not ReadableBuffer.mark() operation is supported for this buffer.
      Specified by:
      markSupported in interface ReadableBuffer
      Overrides:
      markSupported in class AbstractReadableBuffer
    • 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
      Overrides:
      mark in class AbstractReadableBuffer
    • reset

      public void reset()
      Description copied from interface: ReadableBuffer
      Repositions this buffer to the position at the time ReadableBuffer.mark() was last called on this buffer.
      Specified by:
      reset in interface ReadableBuffer
      Overrides:
      reset in class AbstractReadableBuffer
    • byteBufferSupported

      public boolean byteBufferSupported()
      Description copied from interface: ReadableBuffer
      Indicates whether or not ReadableBuffer.getByteBuffer() operation is supported for this buffer.
      Specified by:
      byteBufferSupported in interface ReadableBuffer
      Overrides:
      byteBufferSupported in class AbstractReadableBuffer
    • getByteBuffer

      public 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
      Overrides:
      getByteBuffer in class AbstractReadableBuffer