Enum BufferUtils
- java.lang.Object
-
- java.lang.Enum<BufferUtils>
-
- tech.bitey.bufferstuff.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.ByteBufferEMPTY_BUFFERAn empty, read-onlyByteBufferwhich hasnative order
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.nio.ByteBufferallocate(int capacity)Allocates a newByteBufferwith the specified capacity.static java.nio.ByteBufferallocate(int capacity, java.nio.ByteOrder order)Allocates a newByteBufferwith the specified capacity.static java.nio.ByteBufferasReadOnlyBuffer(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.ByteBuffercopy(java.nio.ByteBuffer b, int fromIndex, int toIndex)Returns a copy of a range from the specified buffer.static java.nio.DoubleBuffercopy(java.nio.DoubleBuffer b, int fromIndex, int toIndex)Returns a copy of a range from the specified buffer.static java.nio.FloatBuffercopy(java.nio.FloatBuffer b, int fromIndex, int toIndex)Returns a copy of a range from the specified buffer.static java.nio.IntBuffercopy(java.nio.IntBuffer b, int fromIndex, int toIndex)Returns a copy of a range from the specified buffer.static java.nio.LongBuffercopy(java.nio.LongBuffer b, int fromIndex, int toIndex)Returns a copy of a range from the specified buffer.static java.nio.ShortBuffercopy(java.nio.ShortBuffer b, int fromIndex, int toIndex)Returns a copy of a range from the specified buffer.static intdeduplicate(java.nio.ByteBuffer b, int fromIndex, int toIndex)Deduplicates a range of the specifiedByteBuffer.static intdeduplicate(java.nio.DoubleBuffer b, int fromIndex, int toIndex)Deduplicates a range of the specifiedDoubleBuffer.static intdeduplicate(java.nio.FloatBuffer b, int fromIndex, int toIndex)Deduplicates a range of the specifiedFloatBuffer.static intdeduplicate(java.nio.IntBuffer b, int fromIndex, int toIndex)Deduplicates a range of the specifiedIntBuffer.static intdeduplicate(java.nio.LongBuffer b, int fromIndex, int toIndex)Deduplicates a range of the specifiedLongBuffer.static intdeduplicate(java.nio.ShortBuffer b, int fromIndex, int toIndex)Deduplicates a range of the specifiedShortBuffer.static java.nio.ByteBufferduplicate(java.nio.ByteBuffer b)Duplicate aByteBufferand preserve the order.static booleanisSorted(java.nio.ByteBuffer b, int fromIndex, int toIndex)Determines if the specified buffer is sorted inside the specified range.static booleanisSorted(java.nio.DoubleBuffer b, int fromIndex, int toIndex)Determines if the specified buffer is sorted inside the specified range.static booleanisSorted(java.nio.FloatBuffer b, int fromIndex, int toIndex)Determines if the specified buffer is sorted inside the specified range.static booleanisSorted(java.nio.IntBuffer b, int fromIndex, int toIndex)Determines if the specified buffer is sorted inside the specified range.static booleanisSorted(java.nio.LongBuffer b, int fromIndex, int toIndex)Determines if the specified buffer is sorted inside the specified range.static booleanisSorted(java.nio.ShortBuffer b, int fromIndex, int toIndex)Determines if the specified buffer is sorted inside the specified range.static booleanisSortedAndDistinct(java.nio.ByteBuffer b, int fromIndex, int toIndex)Determines if the specified buffer is sorted and distinct inside the specified range.static booleanisSortedAndDistinct(java.nio.DoubleBuffer b, int fromIndex, int toIndex)Determines if the specified buffer is sorted and distinct inside the specified range.static booleanisSortedAndDistinct(java.nio.FloatBuffer b, int fromIndex, int toIndex)Determines if the specified buffer is sorted and distinct inside the specified range.static booleanisSortedAndDistinct(java.nio.IntBuffer b, int fromIndex, int toIndex)Determines if the specified buffer is sorted and distinct inside the specified range.static booleanisSortedAndDistinct(java.nio.LongBuffer b, int fromIndex, int toIndex)Determines if the specified buffer is sorted and distinct inside the specified range.static booleanisSortedAndDistinct(java.nio.ShortBuffer b, int fromIndex, int toIndex)Determines if the specified buffer is sorted and distinct inside the specified range.static voidreadFully(java.nio.channels.ReadableByteChannel channel, java.nio.ByteBuffer buffer)Reads bytes from the givenchanneluntil the given buffer is full (remainingis0).static java.nio.ByteBufferslice(java.nio.ByteBuffer b)Slice aByteBufferand preserve the order.static java.nio.ByteBufferslice(java.nio.ByteBuffer b, int fromIndex, int toIndex)Slice a range from the specifiedByteBuffer.static java.util.stream.DoubleStreamstream(java.nio.DoubleBuffer buffer)Returns a sequentialDoubleStreamwith the specified buffer as its source.static java.util.stream.DoubleStreamstream(java.nio.DoubleBuffer buffer, int startInclusive, int endExclusive, int characteristics)Returns a sequentialDoubleStreamwith the specified range of the specified buffer as its source.static java.util.stream.IntStreamstream(java.nio.IntBuffer buffer)Returns a sequentialIntStreamwith the specified buffer as its source.static java.util.stream.IntStreamstream(java.nio.IntBuffer buffer, int startInclusive, int endExclusive, int characteristics)Returns a sequentialIntStreamwith the specified range of the specified buffer as its source.static java.util.stream.LongStreamstream(java.nio.LongBuffer buffer)Returns a sequentialLongStreamwith the specified buffer as its source.static java.util.stream.LongStreamstream(java.nio.LongBuffer buffer, int startInclusive, int endExclusive, int characteristics)Returns a sequentialLongStreamwith the specified range of the specified buffer as its source.static BufferUtilsvalueOf(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 voidwriteFully(java.nio.channels.WritableByteChannel channel, java.nio.ByteBuffer buffer)Writes allremainingbytes from the givenbufferinto the givenchannel.
-
-
-
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 namejava.lang.NullPointerException- if the argument is null
-
allocate
public static java.nio.ByteBuffer allocate(int capacity)
Allocates a newByteBufferwith the specified capacity. The buffer will be direct if thetech.bitey.allocateDirectsystem property is set to "true", and will havenative 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 newByteBufferwith the specified capacity. The buffer will be direct if thetech.bitey.allocateDirectsystem property is set to "true", and will have the specifiedByteOrder.- Parameters:
capacity- the new buffer's capacity, in bytesorder- theByteOrder- Returns:
- the new
ByteBuffer
-
duplicate
public static java.nio.ByteBuffer duplicate(java.nio.ByteBuffer b)
Duplicate aByteBufferand 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 aByteBufferand 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 specifiedByteBuffer. The buffer's order is preserved.- Parameters:
b- - the buffer to be slicedfromIndex- - 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- iffromIndex > toIndexjava.lang.IndexOutOfBoundsException- iffromIndex < 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 checkedfromIndex- - the index of the first element (inclusive) to be checkedtoIndex- - 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- iffromIndex > toIndexjava.lang.IndexOutOfBoundsException- iffromIndex < 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 checkedfromIndex- - the index of the first element (inclusive) to be checkedtoIndex- - 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- iffromIndex > toIndexjava.lang.IndexOutOfBoundsException- iffromIndex < 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 checkedfromIndex- - the index of the first element (inclusive) to be checkedtoIndex- - 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- iffromIndex > toIndexjava.lang.IndexOutOfBoundsException- iffromIndex < 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 checkedfromIndex- - the index of the first element (inclusive) to be checkedtoIndex- - 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- iffromIndex > toIndexjava.lang.IndexOutOfBoundsException- iffromIndex < 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 checkedfromIndex- - the index of the first element (inclusive) to be checkedtoIndex- - 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- iffromIndex > toIndexjava.lang.IndexOutOfBoundsException- iffromIndex < 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 checkedfromIndex- - the index of the first element (inclusive) to be checkedtoIndex- - 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- iffromIndex > toIndexjava.lang.IndexOutOfBoundsException- iffromIndex < 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 checkedfromIndex- - the index of the first element (inclusive) to be checkedtoIndex- - 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- iffromIndex > toIndexjava.lang.IndexOutOfBoundsException- iffromIndex < 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 checkedfromIndex- - the index of the first element (inclusive) to be checkedtoIndex- - 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- iffromIndex > toIndexjava.lang.IndexOutOfBoundsException- iffromIndex < 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 withFloat.compareTo(Float).- Parameters:
b- - the buffer to be checkedfromIndex- - the index of the first element (inclusive) to be checkedtoIndex- - 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- iffromIndex > toIndexjava.lang.IndexOutOfBoundsException- iffromIndex < 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 withFloat.compareTo(Float).- Parameters:
b- - the buffer to be checkedfromIndex- - the index of the first element (inclusive) to be checkedtoIndex- - 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- iffromIndex > toIndexjava.lang.IndexOutOfBoundsException- iffromIndex < 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 withDouble.compareTo(Double).- Parameters:
b- - the buffer to be checkedfromIndex- - the index of the first element (inclusive) to be checkedtoIndex- - 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- iffromIndex > toIndexjava.lang.IndexOutOfBoundsException- iffromIndex < 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 withDouble.compareTo(Double).- Parameters:
b- - the buffer to be checkedfromIndex- - the index of the first element (inclusive) to be checkedtoIndex- - 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- iffromIndex > toIndexjava.lang.IndexOutOfBoundsException- iffromIndex < 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 checkedfromIndex- - the index of the first element (inclusive) to be checkedtoIndex- - 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- iffromIndex > toIndexjava.lang.IndexOutOfBoundsException- iffromIndex < 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 checkedfromIndex- - the index of the first element (inclusive) to be checkedtoIndex- - 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- iffromIndex > toIndexjava.lang.IndexOutOfBoundsException- iffromIndex < 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 checkedfromIndex- - the index of the first element (inclusive) to be checkedtoIndex- - 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- iffromIndex > toIndexjava.lang.IndexOutOfBoundsException- iffromIndex < 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 checkedfromIndex- - the index of the first element (inclusive) to be checkedtoIndex- - 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- iffromIndex > toIndexjava.lang.IndexOutOfBoundsException- iffromIndex < 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 checkedfromIndex- - the index of the first element (inclusive) to be checkedtoIndex- - 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- iffromIndex > toIndexjava.lang.IndexOutOfBoundsException- iffromIndex < 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 checkedfromIndex- - the index of the first element (inclusive) to be checkedtoIndex- - 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- iffromIndex > toIndexjava.lang.IndexOutOfBoundsException- iffromIndex < 0 or toIndex > b.capacity()
-
deduplicate
public static int deduplicate(java.nio.IntBuffer b, int fromIndex, int toIndex)Deduplicates a range of the specifiedIntBuffer. 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 deduplicatedfromIndex- - the index of the first element (inclusive) to be deduplicatedtoIndex- - the index of the last element (exclusive) to be deduplicated- Returns:
- the (exclusive) highest index in use after deduplicating
- Throws:
java.lang.IllegalArgumentException- iffromIndex > toIndexjava.lang.IndexOutOfBoundsException- iffromIndex < 0 or toIndex > b.capacity()
-
deduplicate
public static int deduplicate(java.nio.LongBuffer b, int fromIndex, int toIndex)Deduplicates a range of the specifiedLongBuffer. 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 deduplicatedfromIndex- - the index of the first element (inclusive) to be deduplicatedtoIndex- - the index of the last element (exclusive) to be deduplicated- Returns:
- the (exclusive) highest index in use after deduplicating
- Throws:
java.lang.IllegalArgumentException- iffromIndex > toIndexjava.lang.IndexOutOfBoundsException- iffromIndex < 0 or toIndex > b.capacity()
-
deduplicate
public static int deduplicate(java.nio.ShortBuffer b, int fromIndex, int toIndex)Deduplicates a range of the specifiedShortBuffer. 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 deduplicatedfromIndex- - the index of the first element (inclusive) to be deduplicatedtoIndex- - the index of the last element (exclusive) to be deduplicated- Returns:
- the (exclusive) highest index in use after deduplicating
- Throws:
java.lang.IllegalArgumentException- iffromIndex > toIndexjava.lang.IndexOutOfBoundsException- iffromIndex < 0 or toIndex > b.capacity()
-
deduplicate
public static int deduplicate(java.nio.ByteBuffer b, int fromIndex, int toIndex)Deduplicates a range of the specifiedByteBuffer. 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 deduplicatedfromIndex- - the index of the first element (inclusive) to be deduplicatedtoIndex- - the index of the last element (exclusive) to be deduplicated- Returns:
- the (exclusive) highest index in use after deduplicating
- Throws:
java.lang.IllegalArgumentException- iffromIndex > toIndexjava.lang.IndexOutOfBoundsException- iffromIndex < 0 or toIndex > b.capacity()
-
deduplicate
public static int deduplicate(java.nio.FloatBuffer b, int fromIndex, int toIndex)Deduplicates a range of the specifiedFloatBuffer. 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 deduplicatedfromIndex- - the index of the first element (inclusive) to be deduplicatedtoIndex- - the index of the last element (exclusive) to be deduplicated- Returns:
- the (exclusive) highest index in use after deduplicating
- Throws:
java.lang.IllegalArgumentException- iffromIndex > toIndexjava.lang.IndexOutOfBoundsException- iffromIndex < 0 or toIndex > b.capacity()
-
deduplicate
public static int deduplicate(java.nio.DoubleBuffer b, int fromIndex, int toIndex)Deduplicates a range of the specifiedDoubleBuffer. 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 deduplicatedfromIndex- - the index of the first element (inclusive) to be deduplicatedtoIndex- - the index of the last element (exclusive) to be deduplicated- Returns:
- the (exclusive) highest index in use after deduplicating
- Throws:
java.lang.IllegalArgumentException- iffromIndex > toIndexjava.lang.IndexOutOfBoundsException- iffromIndex < 0 or toIndex > b.capacity()
-
stream
public static java.util.stream.IntStream stream(java.nio.IntBuffer buffer)
Returns a sequentialIntStreamwith the specified buffer as its source.Note: ignores
positionandlimit, can pass asliceinstead.- Parameters:
buffer- the buffer, assumed to be unmodified during use- Returns:
- an
IntStreamfor the buffer
-
stream
public static java.util.stream.IntStream stream(java.nio.IntBuffer buffer, int startInclusive, int endExclusive, int characteristics)Returns a sequentialIntStreamwith the specified range of the specified buffer as its source.- Parameters:
buffer- the buffer, assumed to be unmodified during usestartInclusive- the first index to cover, inclusiveendExclusive- index immediately past the last index to covercharacteristics- characteristics of this spliterator's source or elements beyondSIZED,SUBSIZED,ORDERED,NONNULL, andIMMUTABLE, which are are always reported- Returns:
- an
IntStreamfor the buffer range - Throws:
java.lang.ArrayIndexOutOfBoundsException- ifstartInclusiveis negative,endExclusiveis less thanstartInclusive, orendExclusiveis greater than the buffer'scapacity
-
stream
public static java.util.stream.LongStream stream(java.nio.LongBuffer buffer)
Returns a sequentialLongStreamwith the specified buffer as its source.Note: ignores
positionandlimit, can pass asliceinstead.- Parameters:
buffer- the buffer, assumed to be unmodified during use- Returns:
- an
LongStreamfor the buffer
-
stream
public static java.util.stream.LongStream stream(java.nio.LongBuffer buffer, int startInclusive, int endExclusive, int characteristics)Returns a sequentialLongStreamwith the specified range of the specified buffer as its source.- Parameters:
buffer- the buffer, assumed to be unmodified during usestartInclusive- the first index to cover, inclusiveendExclusive- index immediately past the last index to covercharacteristics- characteristics of this spliterator's source or elements beyondSIZED,SUBSIZED,ORDERED,NONNULL, andIMMUTABLE, which are are always reported- Returns:
- an
LongStreamfor the buffer range - Throws:
java.lang.ArrayIndexOutOfBoundsException- ifstartInclusiveis negative,endExclusiveis less thanstartInclusive, orendExclusiveis greater than the buffer'scapacity
-
stream
public static java.util.stream.DoubleStream stream(java.nio.DoubleBuffer buffer)
Returns a sequentialDoubleStreamwith the specified buffer as its source.Note: ignores
positionandlimit, can pass asliceinstead.- Parameters:
buffer- the buffer, assumed to be unmodified during use- Returns:
- an
DoubleStreamfor the buffer
-
stream
public static java.util.stream.DoubleStream stream(java.nio.DoubleBuffer buffer, int startInclusive, int endExclusive, int characteristics)Returns a sequentialDoubleStreamwith the specified range of the specified buffer as its source.- Parameters:
buffer- the buffer, assumed to be unmodified during usestartInclusive- the first index to cover, inclusiveendExclusive- index immediately past the last index to covercharacteristics- characteristics of this spliterator's source or elements beyondSIZED,SUBSIZED,ORDERED,NONNULL, andIMMUTABLE, which are are always reported- Returns:
- an
DoubleStreamfor the buffer range - Throws:
java.lang.ArrayIndexOutOfBoundsException- ifstartInclusiveis negative,endExclusiveis less thanstartInclusive, orendExclusiveis greater than the buffer'scapacity
-
writeFully
public static void writeFully(java.nio.channels.WritableByteChannel channel, java.nio.ByteBuffer buffer) throws java.io.IOExceptionWrites allremainingbytes from the givenbufferinto the givenchannel.- Parameters:
channel- - the channel being written tobuffer- - 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.IOExceptionReads bytes from the givenchanneluntil the given buffer is full (remainingis0).- Parameters:
channel- - the channel being read frombuffer- - the buffer being written to- Throws:
java.io.IOException
-
-