Class ByteBufferUtils
- java.lang.Object
-
- org.apache.druid.java.util.common.ByteBufferUtils
-
public class ByteBufferUtils extends Object
-
-
Constructor Summary
Constructors Constructor Description ByteBufferUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static ResourceHolder<ByteBuffer>
allocateDirect(int size)
Same asByteBuffer.allocateDirect(int)
, but returns a closeableResourceHolder
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 withString.compareTo(String)
.static void
free(ByteBuffer buffer)
Releases memory held by the given direct ByteBufferstatic void
unmap(MappedByteBuffer buffer)
Un-maps the given memory mapped filestatic Comparator<ByteBuffer>
utf8Comparator()
Comparator that compares twoByteBuffer
using ordering consistent withString.compareTo(String)
.
-
-
-
Method Detail
-
allocateDirect
public static ResourceHolder<ByteBuffer> allocateDirect(int size)
Same asByteBuffer.allocateDirect(int)
, but returns a closeableResourceHolder
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 anIllegalStateException
.
-
free
public static void free(ByteBuffer buffer)
Releases memory held by the given direct ByteBuffer- Parameters:
buffer
- buffer to free
-
unmap
public static void unmap(MappedByteBuffer buffer)
Un-maps the given memory mapped file- Parameters:
buffer
- buffer
-
compareUtf8ByteBuffers
public static int compareUtf8ByteBuffers(@Nullable ByteBuffer buf1, @Nullable ByteBuffer buf2)
Compares two ByteBuffers from their positions to their limits using ordering consistent withString.compareTo(String)
. Null buffers are accepted, and are ordered earlier than any nonnull buffer. Different fromByteBuffer.compareTo(java.nio.ByteBuffer)
, which uses signed-bytes ordering.
-
utf8Comparator
public static Comparator<ByteBuffer> utf8Comparator()
Comparator that compares twoByteBuffer
using ordering consistent withString.compareTo(String)
. Null buffers are accepted, and are ordered earlier than any nonnull buffer.
-
-