public final class ReadableBuffers extends Object
ReadableBuffer
instances.Modifier and Type | Method and Description |
---|---|
static ReadableBuffer |
empty()
Returns an empty
ReadableBuffer instance. |
static ReadableBuffer |
ignoreClose(ReadableBuffer buffer)
Decorates the given
ReadableBuffer to ignore calls to ReadableBuffer.close() . |
static InputStream |
openStream(ReadableBuffer buffer,
boolean owner)
Creates a new
InputStream backed by the given buffer. |
static byte[] |
readArray(ReadableBuffer buffer)
Reads an entire
ReadableBuffer to a new array. |
static String |
readAsString(ReadableBuffer buffer,
Charset charset)
Reads the entire
ReadableBuffer to a new String with the given charset. |
static String |
readAsStringUtf8(ReadableBuffer buffer)
Reads the entire
ReadableBuffer to a new String using UTF-8 decoding. |
static ReadableBuffer |
wrap(byte[] bytes)
Shortcut for
wrap(bytes, 0, bytes.length . |
static ReadableBuffer |
wrap(byte[] bytes,
int offset,
int length)
Creates a new
ReadableBuffer that is backed by the given byte array. |
static ReadableBuffer |
wrap(ByteBuffer bytes)
Creates a new
ReadableBuffer that is backed by the given ByteBuffer . |
public static ReadableBuffer empty()
ReadableBuffer
instance.public static ReadableBuffer wrap(byte[] bytes)
wrap(bytes, 0, bytes.length
.public static ReadableBuffer wrap(byte[] bytes, int offset, int length)
ReadableBuffer
that is backed by the given byte array.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.public static ReadableBuffer wrap(ByteBuffer bytes)
ReadableBuffer
that is backed by the given ByteBuffer
. Calls to
read from the buffer will increment the position of the ByteBuffer
.public static byte[] readArray(ReadableBuffer buffer)
ReadableBuffer
to a new array. After calling this method, the buffer
will contain no readable bytes.public static String readAsString(ReadableBuffer buffer, Charset charset)
ReadableBuffer
to a new String
with the given charset.public static String readAsStringUtf8(ReadableBuffer buffer)
ReadableBuffer
to a new String
using UTF-8 decoding.public static InputStream openStream(ReadableBuffer buffer, boolean owner)
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.buffer
- the buffer backing the new InputStream
.owner
- if true
, the returned stream will close the buffer when closed.public static ReadableBuffer ignoreClose(ReadableBuffer buffer)
ReadableBuffer
to ignore calls to ReadableBuffer.close()
.buffer
- the buffer to be decorated.buffer
that ignores calls to ReadableBuffer.close()
.