Class ByteBufferUtils


  • public class ByteBufferUtils
    extends Object
    • Constructor Detail

      • ByteBufferUtils

        public ByteBufferUtils()
    • Method Detail

      • 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