Package io.grpc.internal
Class ReadableBuffers
java.lang.Object
io.grpc.internal.ReadableBuffers
Utility methods for creating
ReadableBuffer instances.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final classAnInputStreamthat is backed by aReadableBuffer.private static classAReadableBufferthat is backed by a byte array.private static classAReadableBufferthat is backed by aByteBuffer. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ReadableBufferempty()Returns an emptyReadableBufferinstance.static ReadableBufferignoreClose(ReadableBuffer buffer) Decorates the givenReadableBufferto ignore calls toReadableBuffer.close().static InputStreamopenStream(ReadableBuffer buffer, boolean owner) Creates a newInputStreambacked by the given buffer.static byte[]readArray(ReadableBuffer buffer) Reads an entireReadableBufferto a new array.static StringreadAsString(ReadableBuffer buffer, Charset charset) Reads the entireReadableBufferto a newStringwith the given charset.static StringreadAsStringUtf8(ReadableBuffer buffer) Reads the entireReadableBufferto a newStringusing UTF-8 decoding.static ReadableBufferwrap(byte[] bytes) Shortcut forwrap(bytes, 0, bytes.length.static ReadableBufferwrap(byte[] bytes, int offset, int length) Creates a newReadableBufferthat is backed by the given byte array.static ReadableBufferwrap(ByteBuffer bytes) Creates a newReadableBufferthat is backed by the givenByteBuffer.
-
Field Details
-
EMPTY_BUFFER
-
-
Constructor Details
-
ReadableBuffers
private ReadableBuffers()
-
-
Method Details
-
empty
Returns an emptyReadableBufferinstance. -
wrap
Shortcut forwrap(bytes, 0, bytes.length. -
wrap
Creates a newReadableBufferthat 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 theoffsetindex.
-
wrap
Creates a newReadableBufferthat is backed by the givenByteBuffer. Calls to read from the buffer will increment the position of theByteBuffer. -
readArray
Reads an entireReadableBufferto a new array. After calling this method, the buffer will contain no readable bytes. -
readAsString
Reads the entireReadableBufferto a newStringwith the given charset. -
readAsStringUtf8
Reads the entireReadableBufferto a newStringusing UTF-8 decoding. -
openStream
Creates a newInputStreambacked 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 givenReadableBufferto ignore calls toReadableBuffer.close().- Parameters:
buffer- the buffer to be decorated.- Returns:
- a wrapper around
bufferthat ignores calls toReadableBuffer.close().
-