Enum BufferUtils

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<BufferUtils>

    public enum BufferUtils
    extends java.lang.Enum<BufferUtils>
    Utility methods for working with nio buffers.
    Author:
    biteytech@protonmail.com
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.nio.ByteBuffer EMPTY_BUFFER
      An empty, read-only ByteBuffer which has native order
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.nio.ByteBuffer allocate​(int capacity)
      Allocates a new ByteBuffer with the specified capacity.
      static java.nio.ByteBuffer allocate​(int capacity, java.nio.ByteOrder order)
      Allocates a new ByteBuffer with the specified capacity.
      static java.nio.ByteBuffer asReadOnlyBuffer​(java.nio.ByteBuffer b)
      Creates a new, read-only byte buffer that shares the specified buffer's content, and preserves it's order.
      static java.nio.ByteBuffer copy​(java.nio.ByteBuffer b, int fromIndex, int toIndex)
      Returns a copy of a range from the specified buffer.
      static java.nio.DoubleBuffer copy​(java.nio.DoubleBuffer b, int fromIndex, int toIndex)
      Returns a copy of a range from the specified buffer.
      static java.nio.FloatBuffer copy​(java.nio.FloatBuffer b, int fromIndex, int toIndex)
      Returns a copy of a range from the specified buffer.
      static java.nio.IntBuffer copy​(java.nio.IntBuffer b, int fromIndex, int toIndex)
      Returns a copy of a range from the specified buffer.
      static java.nio.LongBuffer copy​(java.nio.LongBuffer b, int fromIndex, int toIndex)
      Returns a copy of a range from the specified buffer.
      static java.nio.ShortBuffer copy​(java.nio.ShortBuffer b, int fromIndex, int toIndex)
      Returns a copy of a range from the specified buffer.
      static int deduplicate​(java.nio.ByteBuffer b, int fromIndex, int toIndex)
      Deduplicates a range of the specified ByteBuffer.
      static int deduplicate​(java.nio.DoubleBuffer b, int fromIndex, int toIndex)
      Deduplicates a range of the specified DoubleBuffer.
      static int deduplicate​(java.nio.FloatBuffer b, int fromIndex, int toIndex)
      Deduplicates a range of the specified FloatBuffer.
      static int deduplicate​(java.nio.IntBuffer b, int fromIndex, int toIndex)
      Deduplicates a range of the specified IntBuffer.
      static int deduplicate​(java.nio.LongBuffer b, int fromIndex, int toIndex)
      Deduplicates a range of the specified LongBuffer.
      static int deduplicate​(java.nio.ShortBuffer b, int fromIndex, int toIndex)
      Deduplicates a range of the specified ShortBuffer.
      static java.nio.ByteBuffer duplicate​(java.nio.ByteBuffer b)
      Duplicate a ByteBuffer and preserve the order.
      static boolean isSorted​(java.nio.ByteBuffer b, int fromIndex, int toIndex)
      Determines if the specified buffer is sorted inside the specified range.
      static boolean isSorted​(java.nio.DoubleBuffer b, int fromIndex, int toIndex)
      Determines if the specified buffer is sorted inside the specified range.
      static boolean isSorted​(java.nio.FloatBuffer b, int fromIndex, int toIndex)
      Determines if the specified buffer is sorted inside the specified range.
      static boolean isSorted​(java.nio.IntBuffer b, int fromIndex, int toIndex)
      Determines if the specified buffer is sorted inside the specified range.
      static boolean isSorted​(java.nio.LongBuffer b, int fromIndex, int toIndex)
      Determines if the specified buffer is sorted inside the specified range.
      static boolean isSorted​(java.nio.ShortBuffer b, int fromIndex, int toIndex)
      Determines if the specified buffer is sorted inside the specified range.
      static boolean isSortedAndDistinct​(java.nio.ByteBuffer b, int fromIndex, int toIndex)
      Determines if the specified buffer is sorted and distinct inside the specified range.
      static boolean isSortedAndDistinct​(java.nio.DoubleBuffer b, int fromIndex, int toIndex)
      Determines if the specified buffer is sorted and distinct inside the specified range.
      static boolean isSortedAndDistinct​(java.nio.FloatBuffer b, int fromIndex, int toIndex)
      Determines if the specified buffer is sorted and distinct inside the specified range.
      static boolean isSortedAndDistinct​(java.nio.IntBuffer b, int fromIndex, int toIndex)
      Determines if the specified buffer is sorted and distinct inside the specified range.
      static boolean isSortedAndDistinct​(java.nio.LongBuffer b, int fromIndex, int toIndex)
      Determines if the specified buffer is sorted and distinct inside the specified range.
      static boolean isSortedAndDistinct​(java.nio.ShortBuffer b, int fromIndex, int toIndex)
      Determines if the specified buffer is sorted and distinct inside the specified range.
      static void readFully​(java.nio.channels.ReadableByteChannel channel, java.nio.ByteBuffer buffer)
      Reads bytes from the given channel until the given buffer is full (remaining is 0).
      static java.nio.ByteBuffer slice​(java.nio.ByteBuffer b)
      Slice a ByteBuffer and preserve the order.
      static java.nio.ByteBuffer slice​(java.nio.ByteBuffer b, int fromIndex, int toIndex)
      Slice a range from the specified ByteBuffer.
      static java.util.stream.DoubleStream stream​(java.nio.DoubleBuffer buffer)
      Returns a sequential DoubleStream with the specified buffer as its source.
      static java.util.stream.DoubleStream stream​(java.nio.DoubleBuffer buffer, int startInclusive, int endExclusive, int characteristics)
      Returns a sequential DoubleStream with the specified range of the specified buffer as its source.
      static java.util.stream.IntStream stream​(java.nio.IntBuffer buffer)
      Returns a sequential IntStream with the specified buffer as its source.
      static java.util.stream.IntStream stream​(java.nio.IntBuffer buffer, int startInclusive, int endExclusive, int characteristics)
      Returns a sequential IntStream with the specified range of the specified buffer as its source.
      static java.util.stream.LongStream stream​(java.nio.LongBuffer buffer)
      Returns a sequential LongStream with the specified buffer as its source.
      static java.util.stream.LongStream stream​(java.nio.LongBuffer buffer, int startInclusive, int endExclusive, int characteristics)
      Returns a sequential LongStream with the specified range of the specified buffer as its source.
      static BufferUtils valueOf​(java.lang.String name)
      Returns the enum constant of this type with the specified name.
      static BufferUtils[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      static void writeFully​(java.nio.channels.WritableByteChannel channel, java.nio.ByteBuffer buffer)
      Writes all remaining bytes from the given buffer into the given channel.
      • Methods inherited from class java.lang.Enum

        clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • EMPTY_BUFFER

        public static final java.nio.ByteBuffer EMPTY_BUFFER
        An empty, read-only ByteBuffer which has native order
    • Method Detail

      • values

        public static BufferUtils[] values()
        Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
        for (BufferUtils c : BufferUtils.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static BufferUtils valueOf​(java.lang.String name)
        Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
        Parameters:
        name - the name of the enum constant to be returned.
        Returns:
        the enum constant with the specified name
        Throws:
        java.lang.IllegalArgumentException - if this enum type has no constant with the specified name
        java.lang.NullPointerException - if the argument is null
      • allocate

        public static java.nio.ByteBuffer allocate​(int capacity)
        Allocates a new ByteBuffer with the specified capacity. The buffer will be direct if the tech.bitey.allocateDirect system property is set to "true", and will have native order.
        Parameters:
        capacity - the new buffer's capacity, in bytes
        Returns:
        the new native order ByteBuffer
      • allocate

        public static java.nio.ByteBuffer allocate​(int capacity,
                                                   java.nio.ByteOrder order)
        Allocates a new ByteBuffer with the specified capacity. The buffer will be direct if the tech.bitey.allocateDirect system property is set to "true", and will have the specified ByteOrder.
        Parameters:
        capacity - the new buffer's capacity, in bytes
        order - the ByteOrder
        Returns:
        the new ByteBuffer
      • duplicate

        public static java.nio.ByteBuffer duplicate​(java.nio.ByteBuffer b)
        Duplicate a ByteBuffer and preserve the order. Equivalent to:
         b.duplicate().order(b.order())
         
        Parameters:
        b - - the buffer to be duplicated
        Returns:
        duplicated buffer with order preserved
        See Also:
        ByteBuffer.duplicate(), ByteBuffer.order()
      • slice

        public static java.nio.ByteBuffer slice​(java.nio.ByteBuffer b)
        Slice a ByteBuffer and preserve the order. Equivalent to:
         b.slice().order(b.order())
         
        Parameters:
        b - - the buffer to be sliced
        Returns:
        sliced buffer with order preserved
        See Also:
        ByteBuffer.slice(), ByteBuffer.order()
      • asReadOnlyBuffer

        public static java.nio.ByteBuffer asReadOnlyBuffer​(java.nio.ByteBuffer b)
        Creates a new, read-only byte buffer that shares the specified buffer's content, and preserves it's order. Equivalent to:
         b.asReadOnlyBuffer().order(b.order())
         
        Parameters:
        b - - the buffer to be made read-only
        Returns:
        read-only byte buffer that shares the specified buffer's content
        See Also:
        ByteBuffer.asReadOnlyBuffer(), ByteBuffer.order()
      • slice

        public static java.nio.ByteBuffer slice​(java.nio.ByteBuffer b,
                                                int fromIndex,
                                                int toIndex)
        Slice a range from the specified ByteBuffer. The buffer's order is preserved.
        Parameters:
        b - - the buffer to be sliced
        fromIndex - - the index of the first element in the range (inclusive)
        toIndex - - the index of the last element in the range (exclusive)
        Returns:
        sliced buffer with order preserved
        Throws:
        java.lang.IllegalArgumentException - if fromIndex > toIndex
        java.lang.IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
        See Also:
        ByteBuffer.slice(), ByteBuffer.order()
      • isSorted

        public static boolean isSorted​(java.nio.IntBuffer b,
                                       int fromIndex,
                                       int toIndex)
        Determines if the specified buffer is sorted inside the specified range. That is: buffer[i] <= buffer[i + 1] for all elements in the range. A range of length zero or one is considered sorted.
        Parameters:
        b - - the buffer to be checked
        fromIndex - - the index of the first element (inclusive) to be checked
        toIndex - - the index of the last element (exclusive) to be checked
        Returns:
        true if the buffer is sorted inside the specified range
        Throws:
        java.lang.IllegalArgumentException - if fromIndex > toIndex
        java.lang.IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
      • isSortedAndDistinct

        public static boolean isSortedAndDistinct​(java.nio.IntBuffer b,
                                                  int fromIndex,
                                                  int toIndex)
        Determines if the specified buffer is sorted and distinct inside the specified range. That is: buffer[i] < buffer[i + 1] for all elements in the range. A range of length zero or one is considered sorted and distinct.
        Parameters:
        b - - the buffer to be checked
        fromIndex - - the index of the first element (inclusive) to be checked
        toIndex - - the index of the last element (exclusive) to be checked
        Returns:
        true if the buffer is sorted and distinct inside the specified range
        Throws:
        java.lang.IllegalArgumentException - if fromIndex > toIndex
        java.lang.IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
      • isSorted

        public static boolean isSorted​(java.nio.LongBuffer b,
                                       int fromIndex,
                                       int toIndex)
        Determines if the specified buffer is sorted inside the specified range. That is: buffer[i] <= buffer[i + 1] for all elements in the range. A range of length zero or one is considered sorted.
        Parameters:
        b - - the buffer to be checked
        fromIndex - - the index of the first element (inclusive) to be checked
        toIndex - - the index of the last element (exclusive) to be checked
        Returns:
        true if the buffer is sorted inside the specified range
        Throws:
        java.lang.IllegalArgumentException - if fromIndex > toIndex
        java.lang.IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
      • isSortedAndDistinct

        public static boolean isSortedAndDistinct​(java.nio.LongBuffer b,
                                                  int fromIndex,
                                                  int toIndex)
        Determines if the specified buffer is sorted and distinct inside the specified range. That is: buffer[i] < buffer[i + 1] for all elements in the range. A range of length zero or one is considered sorted and distinct.
        Parameters:
        b - - the buffer to be checked
        fromIndex - - the index of the first element (inclusive) to be checked
        toIndex - - the index of the last element (exclusive) to be checked
        Returns:
        true if the buffer is sorted and distinct inside the specified range
        Throws:
        java.lang.IllegalArgumentException - if fromIndex > toIndex
        java.lang.IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
      • isSorted

        public static boolean isSorted​(java.nio.ByteBuffer b,
                                       int fromIndex,
                                       int toIndex)
        Determines if the specified buffer is sorted inside the specified range. That is: buffer[i] <= buffer[i + 1] for all elements in the range. A range of length zero or one is considered sorted.
        Parameters:
        b - - the buffer to be checked
        fromIndex - - the index of the first element (inclusive) to be checked
        toIndex - - the index of the last element (exclusive) to be checked
        Returns:
        true if the buffer is sorted inside the specified range
        Throws:
        java.lang.IllegalArgumentException - if fromIndex > toIndex
        java.lang.IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
      • isSortedAndDistinct

        public static boolean isSortedAndDistinct​(java.nio.ByteBuffer b,
                                                  int fromIndex,
                                                  int toIndex)
        Determines if the specified buffer is sorted and distinct inside the specified range. That is: buffer[i] < buffer[i + 1] for all elements in the range. A range of length zero or one is considered sorted and distinct.
        Parameters:
        b - - the buffer to be checked
        fromIndex - - the index of the first element (inclusive) to be checked
        toIndex - - the index of the last element (exclusive) to be checked
        Returns:
        true if the buffer is sorted and distinct inside the specified range
        Throws:
        java.lang.IllegalArgumentException - if fromIndex > toIndex
        java.lang.IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
      • isSorted

        public static boolean isSorted​(java.nio.ShortBuffer b,
                                       int fromIndex,
                                       int toIndex)
        Determines if the specified buffer is sorted inside the specified range. That is: buffer[i] <= buffer[i + 1] for all elements in the range. A range of length zero or one is considered sorted.
        Parameters:
        b - - the buffer to be checked
        fromIndex - - the index of the first element (inclusive) to be checked
        toIndex - - the index of the last element (exclusive) to be checked
        Returns:
        true if the buffer is sorted inside the specified range
        Throws:
        java.lang.IllegalArgumentException - if fromIndex > toIndex
        java.lang.IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
      • isSortedAndDistinct

        public static boolean isSortedAndDistinct​(java.nio.ShortBuffer b,
                                                  int fromIndex,
                                                  int toIndex)
        Determines if the specified buffer is sorted and distinct inside the specified range. That is: buffer[i] < buffer[i + 1] for all elements in the range. A range of length zero or one is considered sorted and distinct.
        Parameters:
        b - - the buffer to be checked
        fromIndex - - the index of the first element (inclusive) to be checked
        toIndex - - the index of the last element (exclusive) to be checked
        Returns:
        true if the buffer is sorted and distinct inside the specified range
        Throws:
        java.lang.IllegalArgumentException - if fromIndex > toIndex
        java.lang.IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
      • isSorted

        public static boolean isSorted​(java.nio.FloatBuffer b,
                                       int fromIndex,
                                       int toIndex)
        Determines if the specified buffer is sorted inside the specified range. That is: buffer[i] <= buffer[i + 1] for all elements in the range. A range of length zero or one is considered sorted. The comparison of two values is consistent with Float.compareTo(Float).
        Parameters:
        b - - the buffer to be checked
        fromIndex - - the index of the first element (inclusive) to be checked
        toIndex - - the index of the last element (exclusive) to be checked
        Returns:
        true if the buffer is sorted inside the specified range
        Throws:
        java.lang.IllegalArgumentException - if fromIndex > toIndex
        java.lang.IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
      • isSortedAndDistinct

        public static boolean isSortedAndDistinct​(java.nio.FloatBuffer b,
                                                  int fromIndex,
                                                  int toIndex)
        Determines if the specified buffer is sorted and distinct inside the specified range. That is: buffer[i] < buffer[i + 1] for all elements in the range. A range of length zero or one is considered sorted and distinct. The comparison of two values is consistent with Float.compareTo(Float).
        Parameters:
        b - - the buffer to be checked
        fromIndex - - the index of the first element (inclusive) to be checked
        toIndex - - the index of the last element (exclusive) to be checked
        Returns:
        true if the buffer is sorted and distinct inside the specified range
        Throws:
        java.lang.IllegalArgumentException - if fromIndex > toIndex
        java.lang.IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
      • isSorted

        public static boolean isSorted​(java.nio.DoubleBuffer b,
                                       int fromIndex,
                                       int toIndex)
        Determines if the specified buffer is sorted inside the specified range. That is: buffer[i] <= buffer[i + 1] for all elements in the range. A range of length zero or one is considered sorted. The comparison of two values is consistent with Double.compareTo(Double).
        Parameters:
        b - - the buffer to be checked
        fromIndex - - the index of the first element (inclusive) to be checked
        toIndex - - the index of the last element (exclusive) to be checked
        Returns:
        true if the buffer is sorted inside the specified range
        Throws:
        java.lang.IllegalArgumentException - if fromIndex > toIndex
        java.lang.IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
      • isSortedAndDistinct

        public static boolean isSortedAndDistinct​(java.nio.DoubleBuffer b,
                                                  int fromIndex,
                                                  int toIndex)
        Determines if the specified buffer is sorted and distinct inside the specified range. That is: buffer[i] < buffer[i + 1] for all elements in the range. A range of length zero or one is considered sorted and distinct. The comparison of two values is consistent with Double.compareTo(Double).
        Parameters:
        b - - the buffer to be checked
        fromIndex - - the index of the first element (inclusive) to be checked
        toIndex - - the index of the last element (exclusive) to be checked
        Returns:
        true if the buffer is sorted and distinct inside the specified range
        Throws:
        java.lang.IllegalArgumentException - if fromIndex > toIndex
        java.lang.IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
      • copy

        public static java.nio.ByteBuffer copy​(java.nio.ByteBuffer b,
                                               int fromIndex,
                                               int toIndex)
        Returns a copy of a range from the specified buffer. The new buffer will be direct iff the specified buffer is direct, and will have the same byte order. The capacity will be equal to the size of the specified range. The limit will be set to the capacity, and the position will be set to zero.
        Parameters:
        b - - the buffer to be checked
        fromIndex - - the index of the first element (inclusive) to be checked
        toIndex - - the index of the last element (exclusive) to be checked
        Returns:
        a copy of a range of data from the specified buffer
        Throws:
        java.lang.IllegalArgumentException - if fromIndex > toIndex
        java.lang.IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
      • copy

        public static java.nio.IntBuffer copy​(java.nio.IntBuffer b,
                                              int fromIndex,
                                              int toIndex)
        Returns a copy of a range from the specified buffer. The new buffer will be direct iff the specified buffer is direct, and will have the same byte order. The capacity will be equal to the size of the specified range. The limit will be set to the capacity, and the position will be set to zero.
        Parameters:
        b - - the buffer to be checked
        fromIndex - - the index of the first element (inclusive) to be checked
        toIndex - - the index of the last element (exclusive) to be checked
        Returns:
        a copy of a range of data from the specified buffer
        Throws:
        java.lang.IllegalArgumentException - if fromIndex > toIndex
        java.lang.IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
      • copy

        public static java.nio.LongBuffer copy​(java.nio.LongBuffer b,
                                               int fromIndex,
                                               int toIndex)
        Returns a copy of a range from the specified buffer. The new buffer will be direct iff the specified buffer is direct, and will have the same byte order. The capacity will be equal to the size of the specified range. The limit will be set to the capacity, and the position will be set to zero.
        Parameters:
        b - - the buffer to be checked
        fromIndex - - the index of the first element (inclusive) to be checked
        toIndex - - the index of the last element (exclusive) to be checked
        Returns:
        a copy of a range of data from the specified buffer
        Throws:
        java.lang.IllegalArgumentException - if fromIndex > toIndex
        java.lang.IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
      • copy

        public static java.nio.ShortBuffer copy​(java.nio.ShortBuffer b,
                                                int fromIndex,
                                                int toIndex)
        Returns a copy of a range from the specified buffer. The new buffer will be direct iff the specified buffer is direct, and will have the same byte order. The capacity will be equal to the size of the specified range. The limit will be set to the capacity, and the position will be set to zero.
        Parameters:
        b - - the buffer to be checked
        fromIndex - - the index of the first element (inclusive) to be checked
        toIndex - - the index of the last element (exclusive) to be checked
        Returns:
        a copy of a range of data from the specified buffer
        Throws:
        java.lang.IllegalArgumentException - if fromIndex > toIndex
        java.lang.IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
      • copy

        public static java.nio.FloatBuffer copy​(java.nio.FloatBuffer b,
                                                int fromIndex,
                                                int toIndex)
        Returns a copy of a range from the specified buffer. The new buffer will be direct iff the specified buffer is direct, and will have the same byte order. The capacity will be equal to the size of the specified range. The limit will be set to the capacity, and the position will be set to zero.
        Parameters:
        b - - the buffer to be checked
        fromIndex - - the index of the first element (inclusive) to be checked
        toIndex - - the index of the last element (exclusive) to be checked
        Returns:
        a copy of a range of data from the specified buffer
        Throws:
        java.lang.IllegalArgumentException - if fromIndex > toIndex
        java.lang.IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
      • copy

        public static java.nio.DoubleBuffer copy​(java.nio.DoubleBuffer b,
                                                 int fromIndex,
                                                 int toIndex)
        Returns a copy of a range from the specified buffer. The new buffer will be direct iff the specified buffer is direct, and will have the same byte order. The capacity will be equal to the size of the specified range. The limit will be set to the capacity, and the position will be set to zero.
        Parameters:
        b - - the buffer to be checked
        fromIndex - - the index of the first element (inclusive) to be checked
        toIndex - - the index of the last element (exclusive) to be checked
        Returns:
        a copy of a range of data from the specified buffer
        Throws:
        java.lang.IllegalArgumentException - if fromIndex > toIndex
        java.lang.IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
      • deduplicate

        public static int deduplicate​(java.nio.IntBuffer b,
                                      int fromIndex,
                                      int toIndex)
        Deduplicates a range of the specified IntBuffer. The range must be sorted in ascending order prior to making this call. If it is not sorted, the results are undefined.

        This method is useful as a post-processing step after a sort on a buffer which contains duplicate elements.

        Parameters:
        b - the buffer to be deduplicated
        fromIndex - - the index of the first element (inclusive) to be deduplicated
        toIndex - - the index of the last element (exclusive) to be deduplicated
        Returns:
        the (exclusive) highest index in use after deduplicating
        Throws:
        java.lang.IllegalArgumentException - if fromIndex > toIndex
        java.lang.IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
      • deduplicate

        public static int deduplicate​(java.nio.LongBuffer b,
                                      int fromIndex,
                                      int toIndex)
        Deduplicates a range of the specified LongBuffer. The range must be sorted in ascending order prior to making this call. If it is not sorted, the results are undefined.

        This method is useful as a post-processing step after a sort on a buffer which contains duplicate elements.

        Parameters:
        b - the buffer to be deduplicated
        fromIndex - - the index of the first element (inclusive) to be deduplicated
        toIndex - - the index of the last element (exclusive) to be deduplicated
        Returns:
        the (exclusive) highest index in use after deduplicating
        Throws:
        java.lang.IllegalArgumentException - if fromIndex > toIndex
        java.lang.IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
      • deduplicate

        public static int deduplicate​(java.nio.ShortBuffer b,
                                      int fromIndex,
                                      int toIndex)
        Deduplicates a range of the specified ShortBuffer. The range must be sorted in ascending order prior to making this call. If it is not sorted, the results are undefined.

        This method is useful as a post-processing step after a sort on a buffer which contains duplicate elements.

        Parameters:
        b - the buffer to be deduplicated
        fromIndex - - the index of the first element (inclusive) to be deduplicated
        toIndex - - the index of the last element (exclusive) to be deduplicated
        Returns:
        the (exclusive) highest index in use after deduplicating
        Throws:
        java.lang.IllegalArgumentException - if fromIndex > toIndex
        java.lang.IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
      • deduplicate

        public static int deduplicate​(java.nio.ByteBuffer b,
                                      int fromIndex,
                                      int toIndex)
        Deduplicates a range of the specified ByteBuffer. The range must be sorted in ascending order prior to making this call. If it is not sorted, the results are undefined.

        This method is useful as a post-processing step after a sort on a buffer which contains duplicate elements.

        Parameters:
        b - the buffer to be deduplicated
        fromIndex - - the index of the first element (inclusive) to be deduplicated
        toIndex - - the index of the last element (exclusive) to be deduplicated
        Returns:
        the (exclusive) highest index in use after deduplicating
        Throws:
        java.lang.IllegalArgumentException - if fromIndex > toIndex
        java.lang.IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
      • deduplicate

        public static int deduplicate​(java.nio.FloatBuffer b,
                                      int fromIndex,
                                      int toIndex)
        Deduplicates a range of the specified FloatBuffer. The range must be sorted in ascending order prior to making this call. If it is not sorted, the results are undefined. This method considers all NaN values to be equivalent and equal.

        This method is useful as a post-processing step after a sort on a buffer which contains duplicate elements.

        Parameters:
        b - the buffer to be deduplicated
        fromIndex - - the index of the first element (inclusive) to be deduplicated
        toIndex - - the index of the last element (exclusive) to be deduplicated
        Returns:
        the (exclusive) highest index in use after deduplicating
        Throws:
        java.lang.IllegalArgumentException - if fromIndex > toIndex
        java.lang.IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
      • deduplicate

        public static int deduplicate​(java.nio.DoubleBuffer b,
                                      int fromIndex,
                                      int toIndex)
        Deduplicates a range of the specified DoubleBuffer. The range must be sorted in ascending order prior to making this call. If it is not sorted, the results are undefined. This method considers all NaN values to be equivalent and equal.

        This method is useful as a post-processing step after a sort on a buffer which contains duplicate elements.

        Parameters:
        b - the buffer to be deduplicated
        fromIndex - - the index of the first element (inclusive) to be deduplicated
        toIndex - - the index of the last element (exclusive) to be deduplicated
        Returns:
        the (exclusive) highest index in use after deduplicating
        Throws:
        java.lang.IllegalArgumentException - if fromIndex > toIndex
        java.lang.IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
      • stream

        public static java.util.stream.IntStream stream​(java.nio.IntBuffer buffer)
        Returns a sequential IntStream with the specified buffer as its source.

        Note: ignores position and limit, can pass a slice instead.

        Parameters:
        buffer - the buffer, assumed to be unmodified during use
        Returns:
        an IntStream for the buffer
      • stream

        public static java.util.stream.IntStream stream​(java.nio.IntBuffer buffer,
                                                        int startInclusive,
                                                        int endExclusive,
                                                        int characteristics)
        Returns a sequential IntStream with the specified range of the specified buffer as its source.
        Parameters:
        buffer - the buffer, assumed to be unmodified during use
        startInclusive - the first index to cover, inclusive
        endExclusive - index immediately past the last index to cover
        characteristics - characteristics of this spliterator's source or elements beyond SIZED, SUBSIZED, ORDERED, NONNULL, and IMMUTABLE, which are are always reported
        Returns:
        an IntStream for the buffer range
        Throws:
        java.lang.ArrayIndexOutOfBoundsException - if startInclusive is negative, endExclusive is less than startInclusive, or endExclusive is greater than the buffer's capacity
      • stream

        public static java.util.stream.LongStream stream​(java.nio.LongBuffer buffer)
        Returns a sequential LongStream with the specified buffer as its source.

        Note: ignores position and limit, can pass a slice instead.

        Parameters:
        buffer - the buffer, assumed to be unmodified during use
        Returns:
        an LongStream for the buffer
      • stream

        public static java.util.stream.LongStream stream​(java.nio.LongBuffer buffer,
                                                         int startInclusive,
                                                         int endExclusive,
                                                         int characteristics)
        Returns a sequential LongStream with the specified range of the specified buffer as its source.
        Parameters:
        buffer - the buffer, assumed to be unmodified during use
        startInclusive - the first index to cover, inclusive
        endExclusive - index immediately past the last index to cover
        characteristics - characteristics of this spliterator's source or elements beyond SIZED, SUBSIZED, ORDERED, NONNULL, and IMMUTABLE, which are are always reported
        Returns:
        an LongStream for the buffer range
        Throws:
        java.lang.ArrayIndexOutOfBoundsException - if startInclusive is negative, endExclusive is less than startInclusive, or endExclusive is greater than the buffer's capacity
      • stream

        public static java.util.stream.DoubleStream stream​(java.nio.DoubleBuffer buffer)
        Returns a sequential DoubleStream with the specified buffer as its source.

        Note: ignores position and limit, can pass a slice instead.

        Parameters:
        buffer - the buffer, assumed to be unmodified during use
        Returns:
        an DoubleStream for the buffer
      • stream

        public static java.util.stream.DoubleStream stream​(java.nio.DoubleBuffer buffer,
                                                           int startInclusive,
                                                           int endExclusive,
                                                           int characteristics)
        Returns a sequential DoubleStream with the specified range of the specified buffer as its source.
        Parameters:
        buffer - the buffer, assumed to be unmodified during use
        startInclusive - the first index to cover, inclusive
        endExclusive - index immediately past the last index to cover
        characteristics - characteristics of this spliterator's source or elements beyond SIZED, SUBSIZED, ORDERED, NONNULL, and IMMUTABLE, which are are always reported
        Returns:
        an DoubleStream for the buffer range
        Throws:
        java.lang.ArrayIndexOutOfBoundsException - if startInclusive is negative, endExclusive is less than startInclusive, or endExclusive is greater than the buffer's capacity
      • writeFully

        public static void writeFully​(java.nio.channels.WritableByteChannel channel,
                                      java.nio.ByteBuffer buffer)
                               throws java.io.IOException
        Writes all remaining bytes from the given buffer into the given channel.
        Parameters:
        channel - - the channel being written to
        buffer - - the buffer being read from
        Throws:
        java.io.IOException
      • readFully

        public static void readFully​(java.nio.channels.ReadableByteChannel channel,
                                     java.nio.ByteBuffer buffer)
                              throws java.io.IOException
        Reads bytes from the given channel until the given buffer is full (remaining is 0).
        Parameters:
        channel - - the channel being read from
        buffer - - the buffer being written to
        Throws:
        java.io.IOException