public final class Persistables extends Object
Persistable
s and/or ByteBuffer
s.Modifier and Type | Method and Description |
---|---|
static ByteBuffer |
copyOf(ByteBuffer buffer)
Returns a newly-allocated copy of a given
ByteBuffer 's remaining contents. |
static Persistable |
persistable(ByteBuffer buffer)
Converts a
ByteBuffer into a Persistable . |
static Persistable |
persistable(Streamable streamable)
Converts a
Streamable into a Persistable . |
static ByteBuffer |
slice(ByteBuffer buffer,
int length)
Returns a newly allocated
ByteBuffer.slice() , starting from the current position , of
a given ByteBuffer . |
static ByteBuffer |
slice(ByteBuffer buffer,
int start,
int length)
Returns a newly allocated
ByteBuffer.slice() of a given ByteBuffer . |
static byte[] |
toByteArray(ByteBuffer buffer)
Returns an array containing a
ByteBuffer 's remaining contents. |
public static Persistable persistable(Streamable streamable)
Streamable
into a Persistable
.streamable
- A Streamable
object.Persistable
representation of the given object.public static Persistable persistable(ByteBuffer buffer)
ByteBuffer
into a Persistable
.buffer
- The bufferpublic static byte[] toByteArray(ByteBuffer buffer)
ByteBuffer
's remaining
contents. position
will remain unchanged.buffer
- The buffer to write into the array.buffer.remaining()
containing the buffer's contents.public static ByteBuffer copyOf(ByteBuffer buffer)
ByteBuffer
's remaining
contents. position
will be unchanged, and the
returned buffer's position will be 0.
This method is not thread-safe.
buffer
- The buffer to copy.remaining
contents.public static ByteBuffer slice(ByteBuffer buffer, int start, int length)
ByteBuffer.slice()
of a given ByteBuffer
. The slice and the original buffer will
share their contents. position
will
be unchanged, and the returned buffer's position will be 0.
This method is not thread-safe.
buffer
- The buffer to slice.start
- The position of the slice's start in the given buffer.length
- The length in bytes of the slice.ByteBuffer.slice()
public static ByteBuffer slice(ByteBuffer buffer, int length)
ByteBuffer.slice()
, starting from the current position
, of
a given ByteBuffer
. The slice and the original buffer will share their contents. position
will have advanced by length
, and the returned
buffer's position will be 0.
This method is not thread-safe.
buffer
- The buffer to slice.length
- The length in bytes of the slice.ByteBuffer.slice()