Class ReadableBuffers

java.lang.Object
io.grpc.internal.ReadableBuffers

public final class ReadableBuffers extends Object
Utility methods for creating ReadableBuffer instances.
  • Method Details

    • empty

      public static ReadableBuffer empty()
      Returns an empty ReadableBuffer instance.
    • wrap

      public static ReadableBuffer wrap(byte[] bytes)
      Shortcut for wrap(bytes, 0, bytes.length.
    • wrap

      public static ReadableBuffer wrap(byte[] bytes, int offset, int length)
      Creates a new ReadableBuffer that is backed by the given byte array.
      Parameters:
      bytes - the byte array being wrapped.
      offset - the starting offset for the buffer within the byte array.
      length - the length of the buffer from the offset index.
    • wrap

      public static ReadableBuffer wrap(ByteBuffer bytes)
      Creates a new ReadableBuffer that is backed by the given ByteBuffer. Calls to read from the buffer will increment the position of the ByteBuffer.
    • readArray

      public static byte[] readArray(ReadableBuffer buffer)
      Reads an entire ReadableBuffer to a new array. After calling this method, the buffer will contain no readable bytes.
    • readAsString

      public static String readAsString(ReadableBuffer buffer, Charset charset)
      Reads the entire ReadableBuffer to a new String with the given charset.
    • readAsStringUtf8

      public static String readAsStringUtf8(ReadableBuffer buffer)
      Reads the entire ReadableBuffer to a new String using UTF-8 decoding.
    • openStream

      public static InputStream openStream(ReadableBuffer buffer, boolean owner)
      Creates a new InputStream backed by the given buffer. Any read taken on the stream will automatically increment the read position of this buffer. Closing the stream, however, does not affect the original buffer.
      Parameters:
      buffer - the buffer backing the new InputStream.
      owner - if true, the returned stream will close the buffer when closed.
    • ignoreClose

      public static ReadableBuffer ignoreClose(ReadableBuffer buffer)
      Decorates the given ReadableBuffer to ignore calls to ReadableBuffer.close().
      Parameters:
      buffer - the buffer to be decorated.
      Returns:
      a wrapper around buffer that ignores calls to ReadableBuffer.close().