public class ByteBufferUtils extends Object
| Constructor and Description |
|---|
ByteBufferUtils() |
| Modifier and Type | Method and Description |
|---|---|
static ResourceHolder<ByteBuffer> |
allocateDirect(int size)
Same as
ByteBuffer.allocateDirect(int), but returns a closeable ResourceHolder that
frees the buffer upon close. |
static int |
compareUtf8ByteBuffers(ByteBuffer buf1,
ByteBuffer buf2)
Compares two ByteBuffers from their positions to their limits using ordering consistent with
String.compareTo(String). |
static void |
free(ByteBuffer buffer)
Releases memory held by the given direct ByteBuffer
|
static void |
unmap(MappedByteBuffer buffer)
Un-maps the given memory mapped file
|
static Comparator<ByteBuffer> |
utf8Comparator()
Comparator that compares two
ByteBuffer using ordering consistent with String.compareTo(String). |
public static ResourceHolder<ByteBuffer> allocateDirect(int size)
ByteBuffer.allocateDirect(int), but returns a closeable ResourceHolder that
frees the buffer upon close.
Direct (off-heap) buffers are an alternative to on-heap buffers that allow memory to be managed
outside the purview of the garbage collector. It's most useful when allocating big chunks of memory,
like processing buffers.
Holders cannot be closed more than once. Attempting to close a holder twice will earn you an
IllegalStateException.public static void free(ByteBuffer buffer)
buffer - buffer to freepublic static void unmap(MappedByteBuffer buffer)
buffer - bufferpublic static int compareUtf8ByteBuffers(@Nullable ByteBuffer buf1, @Nullable ByteBuffer buf2)
String.compareTo(String). Null buffers are accepted, and are ordered earlier than any nonnull buffer.
Different from ByteBuffer.compareTo(java.nio.ByteBuffer), which uses signed-bytes ordering.public static Comparator<ByteBuffer> utf8Comparator()
ByteBuffer using ordering consistent with String.compareTo(String).
Null buffers are accepted, and are ordered earlier than any nonnull buffer.Copyright © 2011–2023 The Apache Software Foundation. All rights reserved.