Class ByteBufferUtils

java.lang.Object
org.apache.druid.java.util.common.ByteBufferUtils

public class ByteBufferUtils extends Object
  • Constructor Details

    • ByteBufferUtils

      public ByteBufferUtils()
  • Method Details

    • allocateDirect

      public static ResourceHolder<ByteBuffer> allocateDirect(int size)
      Same as 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.
    • 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 with 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.
    • utf8Comparator

      public static Comparator<ByteBuffer> utf8Comparator()
      Comparator that compares two ByteBuffer using ordering consistent with String.compareTo(String). Null buffers are accepted, and are ordered earlier than any nonnull buffer.
    • wrapLE

      public static ByteBuffer wrapLE(byte[] array)
      Wraps a byte array in a little-endian ByteBuffer.
      Parameters:
      array - byte array to wrap
      Returns:
      ByteBuffer wrapping the array with little-endian byte order
    • wrapLE

      public static ByteBuffer wrapLE(byte[] array, int offset, int length)
      Wraps a portion of a byte array in a little-endian ByteBuffer.
      Parameters:
      array - byte array to wrap
      offset - offset within the array
      length - length of the region to wrap
      Returns:
      ByteBuffer wrapping the specified portion with little-endian byte order