Class ByteBufferUtils
java.lang.Object
org.apache.druid.java.util.common.ByteBufferUtils
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ResourceHolder<ByteBuffer> allocateDirect(int size) Same asByteBuffer.allocateDirect(int), but returns a closeableResourceHolderthat frees the buffer upon close.static intcompareUtf8ByteBuffers(ByteBuffer buf1, ByteBuffer buf2) Compares two ByteBuffers from their positions to their limits using ordering consistent withString.compareTo(String).static voidfree(ByteBuffer buffer) Releases memory held by the given direct ByteBufferstatic voidunmap(MappedByteBuffer buffer) Un-maps the given memory mapped filestatic Comparator<ByteBuffer> Comparator that compares twoByteBufferusing ordering consistent withString.compareTo(String).
-
Constructor Details
-
ByteBufferUtils
public ByteBufferUtils()
-
-
Method Details
-
allocateDirect
Same asByteBuffer.allocateDirect(int), but returns a closeableResourceHolderthat 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
Releases memory held by the given direct ByteBuffer- Parameters:
buffer- buffer to free
-
unmap
Un-maps the given memory mapped file- Parameters:
buffer- buffer
-
compareUtf8ByteBuffers
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
Comparator that compares twoByteBufferusing ordering consistent withString.compareTo(String). Null buffers are accepted, and are ordered earlier than any nonnull buffer.
-