Class ByteBuffers


  • public class ByteBuffers
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      ByteBuffers()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.nio.ByteBuffer allocate​(int capacity, java.nio.ByteOrder order)
      The replacement for ByteBuffer.allocate(int) that requires to specify the byte order.
      static java.nio.ByteBuffer allocateDirect​(int capacity, java.nio.ByteOrder order)
      The replacement for ByteBuffer.allocateDirect(int) that requires to specify the byte order.
      static java.nio.ByteBuffer asReadOnlyBuffer​(java.nio.ByteBuffer source)
      This method replaces ByteBuffer.asReadOnlyBuffer(), with the difference that it preserves the source buffer's order in the read-only view.
      static java.nio.ByteBuffer duplicate​(java.nio.ByteBuffer toDuplicate)
      This method replaces ByteBuffer.duplicate(), with the difference that it preserves the source buffer's order in the duplicate.
      static long getAddress​(java.nio.ByteBuffer b)
      Returns the actual native address the given direct ByteBuffer.
      static java.nio.ByteBuffer makeAddressAlignedSlice​(java.nio.ByteBuffer directByteBuffer, int capacity, int alignment)
      Returns a slice of the given direct ByteBuffer, which starting native address is a multiple of the given alignment.
      static java.nio.MappedByteBuffer map​(java.nio.channels.FileChannel channel, java.nio.channels.FileChannel.MapMode mode, long position, long size, java.nio.ByteOrder order)
      The replacement for FileChannel.map(java.nio.channels.FileChannel.MapMode, long, long) that requires to specify the byte order.
      static java.nio.ByteBuffer slice​(java.nio.ByteBuffer toSlice)
      This method replaces ByteBuffer.slice(), with the difference that it preserves the source buffer's order in the slice.
      static java.nio.ByteBuffer wrap​(byte[] array, int offset, int length, java.nio.ByteOrder order)
      The replacement for ByteBuffer.wrap(byte[], int, int) that requires to specify the byte order.
      static java.nio.ByteBuffer wrap​(byte[] array, java.nio.ByteOrder order)
      The replacement for ByteBuffer.wrap(byte[], int, int) that requires to specify the byte order.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • ADDRESS_AVAILABLE

        public static final boolean ADDRESS_AVAILABLE
        This flag indicates whether getAddress(ByteBuffer) utility is available. If it's not (this flag value is false), the method throws UnsupportedOperationException.
    • Constructor Detail

      • ByteBuffers

        public ByteBuffers()
    • Method Detail

      • allocate

        public static java.nio.ByteBuffer allocate​(int capacity,
                                                   java.nio.ByteOrder order)
        The replacement for ByteBuffer.allocate(int) that requires to specify the byte order.
      • wrap

        public static java.nio.ByteBuffer wrap​(byte[] array,
                                               java.nio.ByteOrder order)
        The replacement for ByteBuffer.wrap(byte[], int, int) that requires to specify the byte order.
      • wrap

        public static java.nio.ByteBuffer wrap​(byte[] array,
                                               int offset,
                                               int length,
                                               java.nio.ByteOrder order)
        The replacement for ByteBuffer.wrap(byte[], int, int) that requires to specify the byte order.
      • allocateDirect

        public static java.nio.ByteBuffer allocateDirect​(int capacity,
                                                         java.nio.ByteOrder order)
        The replacement for ByteBuffer.allocateDirect(int) that requires to specify the byte order.
      • map

        public static java.nio.MappedByteBuffer map​(java.nio.channels.FileChannel channel,
                                                    java.nio.channels.FileChannel.MapMode mode,
                                                    long position,
                                                    long size,
                                                    java.nio.ByteOrder order)
                                             throws java.io.IOException
        The replacement for FileChannel.map(java.nio.channels.FileChannel.MapMode, long, long) that requires to specify the byte order.
        Throws:
        java.io.IOException
      • slice

        public static java.nio.ByteBuffer slice​(java.nio.ByteBuffer toSlice)
        This method replaces ByteBuffer.slice(), with the difference that it preserves the source buffer's order in the slice. ByteBuffer.slice() returns a buffer that is always BIG_ENDIAN, that is error-prone.
      • duplicate

        public static java.nio.ByteBuffer duplicate​(java.nio.ByteBuffer toDuplicate)
        This method replaces ByteBuffer.duplicate(), with the difference that it preserves the source buffer's order in the duplicate. ByteBuffer.duplicate() returns a buffer that is always BIG_ENDIAN, that is error-prone.
      • asReadOnlyBuffer

        public static java.nio.ByteBuffer asReadOnlyBuffer​(java.nio.ByteBuffer source)
        This method replaces ByteBuffer.asReadOnlyBuffer(), with the difference that it preserves the source buffer's order in the read-only view. ByteBuffer.asReadOnlyBuffer() returns a buffer that is always BIG_ENDIAN, that is error-prone.
      • getAddress

        public static long getAddress​(java.nio.ByteBuffer b)
        Returns the actual native address the given direct ByteBuffer.
        Returns:
        direct memory address
        Throws:
        java.lang.IllegalArgumentException - if the given ByteBuffer is not direct
        java.lang.UnsupportedOperationException - if ADDRESS_AVAILABLE == false
      • makeAddressAlignedSlice

        public static java.nio.ByteBuffer makeAddressAlignedSlice​(java.nio.ByteBuffer directByteBuffer,
                                                                  int capacity,
                                                                  int alignment)
        Returns a slice of the given direct ByteBuffer, which starting native address is a multiple of the given alignment.
        Parameters:
        directByteBuffer - the buffer to make a slice from
        capacity - the capacity of the aligned slice. Must be a multiple of the given alignment
        alignment - the desired alignment of the starting native address for the returned slice
        Returns:
        an address-aligned slice
        Throws:
        java.lang.IllegalArgumentException - if the given buffer is not direct, or if the capacity and the starting native address of the given buffer don't allow to create a slice with the specified alignment and capacity