Package io.grpc.internal
Class ReadableBuffers
- java.lang.Object
-
- io.grpc.internal.ReadableBuffers
-
public final class ReadableBuffers extends java.lang.ObjectUtility methods for creatingReadableBufferinstances.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classReadableBuffers.BufferInputStreamAnInputStreamthat is backed by aReadableBuffer.private static classReadableBuffers.ByteArrayWrapperAReadableBufferthat is backed by a byte array.private static classReadableBuffers.ByteReadableBufferWrapperAReadableBufferthat is backed by aByteBuffer.
-
Field Summary
Fields Modifier and Type Field Description private static ReadableBufferEMPTY_BUFFER
-
Constructor Summary
Constructors Modifier Constructor Description privateReadableBuffers()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static ReadableBufferempty()Returns an emptyReadableBufferinstance.static ReadableBufferignoreClose(ReadableBuffer buffer)Decorates the givenReadableBufferto ignore calls toReadableBuffer.close().static java.io.InputStreamopenStream(ReadableBuffer buffer, boolean owner)Creates a newInputStreambacked by the given buffer.static byte[]readArray(ReadableBuffer buffer)Reads an entireReadableBufferto a new array.static java.lang.StringreadAsString(ReadableBuffer buffer, java.nio.charset.Charset charset)Reads the entireReadableBufferto a newStringwith the given charset.static java.lang.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(java.nio.ByteBuffer bytes)Creates a newReadableBufferthat is backed by the givenByteBuffer.
-
-
-
Field Detail
-
EMPTY_BUFFER
private static final ReadableBuffer EMPTY_BUFFER
-
-
Method Detail
-
empty
public static ReadableBuffer empty()
Returns an emptyReadableBufferinstance.
-
wrap
public static ReadableBuffer wrap(byte[] bytes)
Shortcut forwrap(bytes, 0, bytes.length.
-
wrap
public static ReadableBuffer wrap(byte[] bytes, int offset, int length)
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
public static ReadableBuffer wrap(java.nio.ByteBuffer bytes)
Creates a newReadableBufferthat is backed by the givenByteBuffer. Calls to read from the buffer will increment the position of theByteBuffer.
-
readArray
public static byte[] readArray(ReadableBuffer buffer)
Reads an entireReadableBufferto a new array. After calling this method, the buffer will contain no readable bytes.
-
readAsString
public static java.lang.String readAsString(ReadableBuffer buffer, java.nio.charset.Charset charset)
Reads the entireReadableBufferto a newStringwith the given charset.
-
readAsStringUtf8
public static java.lang.String readAsStringUtf8(ReadableBuffer buffer)
Reads the entireReadableBufferto a newStringusing UTF-8 decoding.
-
openStream
public static java.io.InputStream openStream(ReadableBuffer buffer, boolean owner)
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
public static ReadableBuffer ignoreClose(ReadableBuffer buffer)
Decorates the givenReadableBufferto ignore calls toReadableBuffer.close().- Parameters:
buffer- the buffer to be decorated.- Returns:
- a wrapper around
bufferthat ignores calls toReadableBuffer.close().
-
-