Package io.grpc.internal
Class ReadableBuffers
java.lang.Object
io.grpc.internal.ReadableBuffers
Utility methods for creating
ReadableBuffer
instances.-
Method Summary
Modifier and TypeMethodDescriptionstatic ReadableBuffer
empty()
Returns an emptyReadableBuffer
instance.static ReadableBuffer
ignoreClose
(ReadableBuffer buffer) Decorates the givenReadableBuffer
to ignore calls toReadableBuffer.close()
.static InputStream
openStream
(ReadableBuffer buffer, boolean owner) Creates a newInputStream
backed by the given buffer.static byte[]
readArray
(ReadableBuffer buffer) Reads an entireReadableBuffer
to a new array.static String
readAsString
(ReadableBuffer buffer, Charset charset) Reads the entireReadableBuffer
to a newString
with the given charset.static String
readAsStringUtf8
(ReadableBuffer buffer) Reads the entireReadableBuffer
to a newString
using UTF-8 decoding.static ReadableBuffer
wrap
(byte[] bytes) Shortcut forwrap(bytes, 0, bytes.length
.static ReadableBuffer
wrap
(byte[] bytes, int offset, int length) Creates a newReadableBuffer
that is backed by the given byte array.static ReadableBuffer
wrap
(ByteBuffer bytes) Creates a newReadableBuffer
that is backed by the givenByteBuffer
.
-
Method Details
-
empty
Returns an emptyReadableBuffer
instance. -
wrap
Shortcut forwrap(bytes, 0, bytes.length
. -
wrap
Creates a newReadableBuffer
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 theoffset
index.
-
wrap
Creates a newReadableBuffer
that is backed by the givenByteBuffer
. Calls to read from the buffer will increment the position of theByteBuffer
. -
readArray
Reads an entireReadableBuffer
to a new array. After calling this method, the buffer will contain no readable bytes. -
readAsString
Reads the entireReadableBuffer
to a newString
with the given charset. -
readAsStringUtf8
Reads the entireReadableBuffer
to a newString
using UTF-8 decoding. -
openStream
Creates a newInputStream
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 newInputStream
.owner
- iftrue
, the returned stream will close the buffer when closed.
-
ignoreClose
Decorates the givenReadableBuffer
to ignore calls toReadableBuffer.close()
.- Parameters:
buffer
- the buffer to be decorated.- Returns:
- a wrapper around
buffer
that ignores calls toReadableBuffer.close()
.
-