Class Buffers
- java.lang.Object
-
- com.jogamp.common.nio.Buffers
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Buffers.Cleaner
Access to NIOsun.misc.Cleaner
, allowing caller to deterministically clean a givenDirectBuffer
.
-
Field Summary
Fields Modifier and Type Field Description static int
SIZEOF_BYTE
static int
SIZEOF_CHAR
static int
SIZEOF_DOUBLE
static int
SIZEOF_FLOAT
static int
SIZEOF_INT
static int
SIZEOF_LONG
static int
SIZEOF_SHORT
-
Constructor Summary
Constructors Modifier Constructor Description protected
Buffers()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static ByteBuffer
copyByteBuffer(ByteBuffer orig)
Copies the remaining elements (as defined bylimit() - position()
) in the passed ByteBuffer into a newly-allocated direct ByteBuffer.static FloatBuffer
copyFloatBuffer(FloatBuffer orig)
Copies the remaining elements (as defined bylimit() - position()
) in the passed FloatBuffer into a newly-allocated direct FloatBuffer.static ByteBuffer
copyFloatBufferAsByteBuffer(FloatBuffer orig)
Copies the remaining elements (as defined bylimit() - position()
) in the passed FloatBuffer into a newly-allocated direct ByteBuffer.static IntBuffer
copyIntBuffer(IntBuffer orig)
Copies the remaining elements (as defined bylimit() - position()
) in the passed IntBuffer into a newly-allocated direct IntBuffer.static ByteBuffer
copyIntBufferAsByteBuffer(IntBuffer orig)
Copies the remaining elements (as defined bylimit() - position()
) in the passed IntBuffer into a newly-allocated direct ByteBuffer.static ByteBuffer
copyNativeToDirectByteBuffer(long source_address, long len)
Copy `len` native bytes @ `source_address` into a newly created directByteBuffer
.static ShortBuffer
copyShortBuffer(ShortBuffer orig)
Copies the remaining elements (as defined bylimit() - position()
) in the passed ShortBuffer into a newly-allocated direct ShortBuffer.static ByteBuffer
copyShortBufferAsByteBuffer(ShortBuffer orig)
Copies the remaining elements (as defined bylimit() - position()
) in the passed ShortBuffer into a newly-allocated direct ByteBuffer.static Object
getArray(Object buf)
Helper routine to return the array backing store reference from a Buffer object.static int
getDirectBufferByteOffset(Object buf)
Helper routine to get the Buffer byte offset by taking into account the Buffer position and the underlying type.static double[]
getDoubleArray(float[] source, int soffset, double[] dest, int doffset, int len)
static DoubleBuffer
getDoubleBuffer(FloatBuffer source, DoubleBuffer dest)
No rewind or repositioning is performed.static float[]
getFloatArray(double[] source, int soffset, float[] dest, int doffset, int len)
static FloatBuffer
getFloatBuffer(DoubleBuffer source, FloatBuffer dest)
No rewind or repositioning is performed.static int
getIndirectBufferByteOffset(Object buf)
Helper routine to get the full byte offset from the beginning of the array that is the storage for the indirect Buffer object.static boolean
isDirect(Object buf)
Helper routine to tell whether a buffer is direct or not.static ByteBuffer
nativeOrder(ByteBuffer buf)
Helper routine to set a ByteBuffer to the native byte order, if that operation is supported by the underlying NIO implementation.static ByteBuffer
newDirectByteBuffer(byte[] values)
static ByteBuffer
newDirectByteBuffer(byte[] values, int offset)
static ByteBuffer
newDirectByteBuffer(byte[] values, int offset, int length)
static ByteBuffer
newDirectByteBuffer(int numElements)
Allocates a new direct ByteBuffer with the specified number of elements.static CharBuffer
newDirectCharBuffer(char[] values)
static CharBuffer
newDirectCharBuffer(char[] values, int offset)
static CharBuffer
newDirectCharBuffer(char[] values, int offset, int length)
static CharBuffer
newDirectCharBuffer(int numElements)
Allocates a new direct CharBuffer with the specified number of elements.static DoubleBuffer
newDirectDoubleBuffer(double[] values)
static DoubleBuffer
newDirectDoubleBuffer(double[] values, int offset)
static DoubleBuffer
newDirectDoubleBuffer(double[] values, int offset, int length)
static DoubleBuffer
newDirectDoubleBuffer(int numElements)
Allocates a new direct DoubleBuffer with the specified number of elements.static FloatBuffer
newDirectFloatBuffer(float[] values)
static FloatBuffer
newDirectFloatBuffer(float[] values, int offset)
static FloatBuffer
newDirectFloatBuffer(float[] values, int offset, int length)
static FloatBuffer
newDirectFloatBuffer(int numElements)
Allocates a new direct FloatBuffer with the specified number of elements.static IntBuffer
newDirectIntBuffer(int numElements)
Allocates a new direct IntBuffer with the specified number of elements.static IntBuffer
newDirectIntBuffer(int[] values)
static IntBuffer
newDirectIntBuffer(int[] values, int offset)
static IntBuffer
newDirectIntBuffer(int[] values, int offset, int length)
static LongBuffer
newDirectLongBuffer(int numElements)
Allocates a new direct LongBuffer with the specified number of elements.static LongBuffer
newDirectLongBuffer(long[] values)
static LongBuffer
newDirectLongBuffer(long[] values, int offset)
static LongBuffer
newDirectLongBuffer(long[] values, int offset, int length)
static ShortBuffer
newDirectShortBuffer(int numElements)
Allocates a new direct ShortBuffer with the specified number of elements.static ShortBuffer
newDirectShortBuffer(short[] values)
static ShortBuffer
newDirectShortBuffer(short[] values, int offset)
static ShortBuffer
newDirectShortBuffer(short[] values, int offset, int length)
static <B extends Buffer>
Bput(B dest, Buffer src)
static <B extends Buffer>
Bput3b(B dest, byte v1, byte v2, byte v3)
static <B extends Buffer>
Bput3d(B dest, double v1, double v2, double v3)
static <B extends Buffer>
Bput3f(B dest, float v1, float v2, float v3)
static <B extends Buffer>
Bput3i(B dest, int v1, int v2, int v3)
static <B extends Buffer>
Bput3s(B dest, short v1, short v2, short v3)
static <B extends Buffer>
Bput4b(B dest, byte v1, byte v2, byte v3, byte v4)
static <B extends Buffer>
Bput4d(B dest, double v1, double v2, double v3, double v4)
static <B extends Buffer>
Bput4f(B dest, float v1, float v2, float v3, float v4)
static <B extends Buffer>
Bput4i(B dest, int v1, int v2, int v3, int v4)
static <B extends Buffer>
Bput4s(B dest, short v1, short v2, short v3, short v4)
static <B extends Buffer>
Bputb(B dest, byte v)
static <B extends Buffer>
Bputb(B dest, byte[] src, int offset, int length)
static <B extends Buffer>
Bputd(B dest, double v)
static <B extends Buffer>
Bputd(B dest, double[] src, int offset, int length)
static <B extends Buffer>
Bputf(B dest, float v)
static <B extends Buffer>
Bputf(B dest, float[] src, int offset, int length)
static <B extends Buffer>
Bputi(B dest, int v)
static <B extends Buffer>
Bputi(B dest, int[] src, int offset, int length)
static <B extends Buffer>
BputNb(B dest, boolean dSigned, byte v, boolean sSigned)
Store byte source value in given buffer after normalizing it to the destination value range considering signed and unsigned source and destination representation.static <B extends Buffer>
BputNf(B dest, boolean dSigned, float v)
Store float source value in given buffer after normalizing it to the destination value range considering signed and unsigned destination representation.static <B extends Buffer>
BputNi(B dest, boolean dSigned, int v, boolean sSigned)
Store short source value in given buffer after normalizing it to the destination value range considering signed and unsigned source and destination representation.static <B extends Buffer>
BputNs(B dest, boolean dSigned, short v, boolean sSigned)
Store short source value in given buffer after normalizing it to the destination value range considering signed and unsigned source and destination representation.static <B extends Buffer>
Bputs(B dest, short v)
static <B extends Buffer>
Bputs(B dest, short[] src, int offset, int length)
static void
rangeCheck(byte[] array, int offset, int minElementsRemaining)
static void
rangeCheck(char[] array, int offset, int minElementsRemaining)
static void
rangeCheck(double[] array, int offset, int minElementsRemaining)
static void
rangeCheck(float[] array, int offset, int minElementsRemaining)
static void
rangeCheck(int[] array, int offset, int minElementsRemaining)
static void
rangeCheck(long[] array, int offset, int minElementsRemaining)
static void
rangeCheck(short[] array, int offset, int minElementsRemaining)
static void
rangeCheck(Buffer buffer, int minElementsRemaining)
static void
rangeCheckBytes(Object buffer, int minBytesRemaining)
static int
remainingBytes(Object buffer)
Returns the number of remaining bytes of the given anonymousbuffer
.static int
remainingElem(Object buffer)
Returns the number of remaining elements of the given anonymousbuffer
.static int
sizeOfBufferElem(Class<? extends Buffer> bufferClz)
Returns the size of a single element of the given buffer class in bytes or0
if the given buffer isnull
.static int
sizeOfBufferElem(Object buffer)
Returns the size of a single element of the given buffer in bytes or0
if the given buffer isnull
.static <B extends Buffer>
Bslice(B buffer)
Calls slice on the specified buffer while maintaining the byteorder.static <B extends Buffer>
Bslice(B buffer, int offset, int size)
Slices the specified buffer with offset as position and offset+size as limit while maintaining the byteorder.static CharBuffer
slice2Char(char[] backing, int elementStartPos, int elementCount)
Slices a primitive float backing array to a CharBuffer at the given `elementStartPos` with the given `elementCount` in short-space bywrapping
the backing array.static CharBuffer
slice2Char(Buffer buf, int elementStartPos, int elementCount)
Slices a ByteBuffer or a CharBuffer to a CharBuffer at the given `elementStartPos` with the given `elementCount` in short-space.static DoubleBuffer
slice2Double(double[] backing, int elementStartPos, int elementCount)
Slices a primitive float backing array to a DoubleBuffer at the given `elementStartPos` with the given `elementCount` in double-space bywrapping
the backing array.static DoubleBuffer
slice2Double(Buffer buf, int elementStartPos, int elementCount)
Slices a ByteBuffer or a DoubleBuffer to a DoubleBuffer at the given `elementStartPos` with the given `elementCount` in double-space.static FloatBuffer
slice2Float(float[] backing, int elementStartPos, int elementCount)
Slices a primitive float backing array to a FloatBuffer at the given `elementStartPos` with the given `elementCount` in float-space bywrapping
the backing array.static FloatBuffer
slice2Float(Buffer buf, int elementStartPos, int elementCount)
Slices a ByteBuffer or a FloatBuffer to a FloatBuffer at the given `elementStartPos` with the given `elementCount` in float-space.static IntBuffer
slice2Int(int[] backing, int elementStartPos, int elementCount)
Slices a primitive float backing array to a IntBuffer at the given `elementStartPos` with the given `elementCount` in int-space bywrapping
the backing array.static IntBuffer
slice2Int(Buffer buf, int elementStartPos, int elementCount)
Slices a ByteBuffer or a IntBuffer to a IntBuffer at the given `elementStartPos` with the given `elementCount` in int-space.static LongBuffer
slice2Long(long[] backing, int elementStartPos, int elementCount)
Slices a primitive float backing array to a LongBuffer at the given `elementStartPos` with the given `elementCount` in long-space bywrapping
the backing array.static LongBuffer
slice2Long(Buffer buf, int elementStartPos, int elementCount)
Slices a ByteBuffer or a LongBuffer to a LongBuffer at the given `elementStartPos` with the given `elementCount` in long-space.static ShortBuffer
slice2Short(short[] backing, int elementStartPos, int elementCount)
Slices a primitive float backing array to a ShortBuffer at the given `elementStartPos` with the given `elementCount` in short-space bywrapping
the backing array.static ShortBuffer
slice2Short(Buffer buf, int elementStartPos, int elementCount)
Slices a ByteBuffer or a ShortBuffer to a ShortBuffer at the given `elementStartPos` with the given `elementCount` in short-space.static int
strnlen(long cstrptr, int maxlen)
Returnsstrnlen(cstrptr, maxlen)
according to POSIX.1-2008.static StringBuilder
toString(StringBuilder sb, String f, Buffer buffer)
Appends Buffer details inclusive data to a StringBuilder instance.static Class<? extends Buffer>
typeNameToBufferClass(String typeName)
ReturnsBuffer
class matching the given lower case `typeName`
-
-
-
Field Detail
-
SIZEOF_BYTE
public static final int SIZEOF_BYTE
- See Also:
- Constant Field Values
-
SIZEOF_SHORT
public static final int SIZEOF_SHORT
- See Also:
- Constant Field Values
-
SIZEOF_CHAR
public static final int SIZEOF_CHAR
- See Also:
- Constant Field Values
-
SIZEOF_INT
public static final int SIZEOF_INT
- See Also:
- Constant Field Values
-
SIZEOF_FLOAT
public static final int SIZEOF_FLOAT
- See Also:
- Constant Field Values
-
SIZEOF_LONG
public static final int SIZEOF_LONG
- See Also:
- Constant Field Values
-
SIZEOF_DOUBLE
public static final int SIZEOF_DOUBLE
- See Also:
- Constant Field Values
-
-
Method Detail
-
newDirectByteBuffer
public static ByteBuffer newDirectByteBuffer(int numElements)
Allocates a new direct ByteBuffer with the specified number of elements. The returned buffer will have its byte order set to the host platform's native byte order.
-
newDirectByteBuffer
public static ByteBuffer newDirectByteBuffer(byte[] values, int offset, int length)
-
newDirectByteBuffer
public static ByteBuffer newDirectByteBuffer(byte[] values, int offset)
-
newDirectByteBuffer
public static ByteBuffer newDirectByteBuffer(byte[] values)
-
newDirectDoubleBuffer
public static DoubleBuffer newDirectDoubleBuffer(int numElements)
Allocates a new direct DoubleBuffer with the specified number of elements. The returned buffer will have its byte order set to the host platform's native byte order.
-
newDirectDoubleBuffer
public static DoubleBuffer newDirectDoubleBuffer(double[] values, int offset, int length)
-
newDirectDoubleBuffer
public static DoubleBuffer newDirectDoubleBuffer(double[] values, int offset)
-
newDirectDoubleBuffer
public static DoubleBuffer newDirectDoubleBuffer(double[] values)
-
newDirectFloatBuffer
public static FloatBuffer newDirectFloatBuffer(int numElements)
Allocates a new direct FloatBuffer with the specified number of elements. The returned buffer will have its byte order set to the host platform's native byte order.
-
newDirectFloatBuffer
public static FloatBuffer newDirectFloatBuffer(float[] values, int offset, int length)
-
newDirectFloatBuffer
public static FloatBuffer newDirectFloatBuffer(float[] values, int offset)
-
newDirectFloatBuffer
public static FloatBuffer newDirectFloatBuffer(float[] values)
-
newDirectIntBuffer
public static IntBuffer newDirectIntBuffer(int numElements)
Allocates a new direct IntBuffer with the specified number of elements. The returned buffer will have its byte order set to the host platform's native byte order.
-
newDirectIntBuffer
public static IntBuffer newDirectIntBuffer(int[] values, int offset, int length)
-
newDirectIntBuffer
public static IntBuffer newDirectIntBuffer(int[] values, int offset)
-
newDirectIntBuffer
public static IntBuffer newDirectIntBuffer(int[] values)
-
newDirectLongBuffer
public static LongBuffer newDirectLongBuffer(int numElements)
Allocates a new direct LongBuffer with the specified number of elements. The returned buffer will have its byte order set to the host platform's native byte order.
-
newDirectLongBuffer
public static LongBuffer newDirectLongBuffer(long[] values, int offset, int length)
-
newDirectLongBuffer
public static LongBuffer newDirectLongBuffer(long[] values, int offset)
-
newDirectLongBuffer
public static LongBuffer newDirectLongBuffer(long[] values)
-
newDirectShortBuffer
public static ShortBuffer newDirectShortBuffer(int numElements)
Allocates a new direct ShortBuffer with the specified number of elements. The returned buffer will have its byte order set to the host platform's native byte order.
-
newDirectShortBuffer
public static ShortBuffer newDirectShortBuffer(short[] values, int offset, int length)
-
newDirectShortBuffer
public static ShortBuffer newDirectShortBuffer(short[] values, int offset)
-
newDirectShortBuffer
public static ShortBuffer newDirectShortBuffer(short[] values)
-
newDirectCharBuffer
public static CharBuffer newDirectCharBuffer(int numElements)
Allocates a new direct CharBuffer with the specified number of elements. The returned buffer will have its byte order set to the host platform's native byte order.
-
newDirectCharBuffer
public static CharBuffer newDirectCharBuffer(char[] values, int offset, int length)
-
newDirectCharBuffer
public static CharBuffer newDirectCharBuffer(char[] values, int offset)
-
newDirectCharBuffer
public static CharBuffer newDirectCharBuffer(char[] values)
-
nativeOrder
public static ByteBuffer nativeOrder(ByteBuffer buf)
Helper routine to set a ByteBuffer to the native byte order, if that operation is supported by the underlying NIO implementation.
-
typeNameToBufferClass
public static Class<? extends Buffer> typeNameToBufferClass(String typeName)
ReturnsBuffer
class matching the given lower case `typeName`- Parameters:
typeName
- lower-case type name- Returns:
- matching
Buffer
class or `null` - See Also:
sizeOfBufferElem(Class)
-
sizeOfBufferElem
public static int sizeOfBufferElem(Class<? extends Buffer> bufferClz)
Returns the size of a single element of the given buffer class in bytes or0
if the given buffer isnull
.
-
sizeOfBufferElem
public static int sizeOfBufferElem(Object buffer)
Returns the size of a single element of the given buffer in bytes or0
if the given buffer isnull
.- See Also:
sizeOfBufferElem(Class)
-
remainingElem
public static int remainingElem(Object buffer) throws IllegalArgumentException
Returns the number of remaining elements of the given anonymousbuffer
.- Parameters:
buffer
- Anonymous Buffer of typeNativeBuffer
or a derivation ofBuffer
.- Returns:
- If
buffer
is null, returns0
, otherwise the remaining size in elements.
- Throws:
IllegalArgumentException
- ifbuffer
is of invalid type.
-
remainingBytes
public static int remainingBytes(Object buffer) throws IllegalArgumentException
Returns the number of remaining bytes of the given anonymousbuffer
.- Parameters:
buffer
- Anonymous Buffer of typeNativeBuffer
or a derivation ofBuffer
.- Returns:
- If
buffer
is null, returns0
, otherwise the remaining size in bytes.
- Throws:
IllegalArgumentException
- ifbuffer
is of invalid type.
-
isDirect
public static boolean isDirect(Object buf)
Helper routine to tell whether a buffer is direct or not. Null pointers are considered direct.
-
getDirectBufferByteOffset
public static int getDirectBufferByteOffset(Object buf)
Helper routine to get the Buffer byte offset by taking into account the Buffer position and the underlying type. This is the total offset for Direct Buffers.
-
getArray
public static Object getArray(Object buf) throws UnsupportedOperationException, IllegalArgumentException
Helper routine to return the array backing store reference from a Buffer object.- Throws:
UnsupportedOperationException
- if the passed Object does not have an array backing storeIllegalArgumentException
- if the passed Object is neither of typeBuffer
orNativeBuffer
.
-
getIndirectBufferByteOffset
public static int getIndirectBufferByteOffset(Object buf)
Helper routine to get the full byte offset from the beginning of the array that is the storage for the indirect Buffer object. The array offset also includes the position offset within the buffer, in addition to any array offset.
-
slice
public static <B extends Buffer> B slice(B buffer)
Calls slice on the specified buffer while maintaining the byteorder.- See Also:
slice(java.nio.Buffer, int, int)
-
slice
public static <B extends Buffer> B slice(B buffer, int offset, int size)
Slices the specified buffer with offset as position and offset+size as limit while maintaining the byteorder. Concurrency warning: this method changes the buffers position and limit but will restore it before return.
-
slice2Float
public static final FloatBuffer slice2Float(Buffer buf, int elementStartPos, int elementCount)
Slices a ByteBuffer or a FloatBuffer to a FloatBuffer at the given `elementStartPos` with the given `elementCount` in float-space.The returned sliced buffer's start position is zero.
The returned sliced buffer is
marked
at it'sstart position
. HenceFloatBuffer.reset()
will rewind it to start after applying relative operations likeFloatBuffer.get()
.Using a ByteBuffer as the source guarantees keeping the source native order programmatically. This works around Honeycomb / Android 3.0 Issue 16434. This bug is resolved at least in Android 3.2.
- Parameters:
buf
- source Buffer, maybe ByteBuffer (recommended) or FloatBuffer. Buffer's position is ignored and `elementStartPos` is being used.elementStartPos
- element start position w/ element of sizeSIZEOF_FLOAT
elementCount
- element count for element of sizeSIZEOF_FLOAT
- Returns:
- FloatBuffer w/ native byte order as given ByteBuffer
-
slice2Float
public static final FloatBuffer slice2Float(float[] backing, int elementStartPos, int elementCount)
Slices a primitive float backing array to a FloatBuffer at the given `elementStartPos` with the given `elementCount` in float-space bywrapping
the backing array.Due to
wrapping
the backing array, the returned sliced buffer'sstart position
equals the givenfloatStartPos
within the given backing array while it'sarray-offset
is zero. This has the advantage of being able to dismiss thearray-offset
in user code, while only being required to consider it'sposition
.The returned sliced buffer is
marked
at it'sstart position
. HenceFloatBuffer.reset()
will rewind it to start after applying relative operations likeFloatBuffer.get()
.- Parameters:
backing
- source float arrayelementStartPos
- element start position w/ element of sizeSIZEOF_FLOAT
elementCount
- element count for element of sizeSIZEOF_FLOAT
- Returns:
- FloatBuffer w/ native byte order as given ByteBuffer
-
slice2Short
public static final ShortBuffer slice2Short(Buffer buf, int elementStartPos, int elementCount)
Slices a ByteBuffer or a ShortBuffer to a ShortBuffer at the given `elementStartPos` with the given `elementCount` in short-space.The returned sliced buffer's start position is zero.
See
slice2Float(Buffer, int, int)
for details.- Parameters:
buf
- source Buffer, maybe ByteBuffer (recommended) or ShortBuffer. Buffer's position is ignored and `elementStartPos` is being used.elementStartPos
- element start position w/ element of sizeSIZEOF_SHORT
elementCount
- element count for element of sizeSIZEOF_SHORT
- Returns:
- ShortBuffer w/ native byte order as given ByteBuffer
- See Also:
slice2Float(Buffer, int, int)
-
slice2Short
public static final ShortBuffer slice2Short(short[] backing, int elementStartPos, int elementCount)
Slices a primitive float backing array to a ShortBuffer at the given `elementStartPos` with the given `elementCount` in short-space bywrapping
the backing array.See
slice2Float(float[], int, int)
for details.- Parameters:
backing
- source float arrayelementStartPos
- element start position w/ element of sizeSIZEOF_SHORT
elementCount
- element count for element of sizeSIZEOF_SHORT
- Returns:
- ShortBuffer w/ native byte order as given ByteBuffer
- See Also:
slice2Float(float[], int, int)
-
slice2Char
public static final CharBuffer slice2Char(Buffer buf, int elementStartPos, int elementCount)
Slices a ByteBuffer or a CharBuffer to a CharBuffer at the given `elementStartPos` with the given `elementCount` in short-space.The returned sliced buffer's start position is zero.
See
slice2Float(Buffer, int, int)
for details.- Parameters:
buf
- source Buffer, maybe ByteBuffer (recommended) or CharBuffer. Buffer's position is ignored and `elementStartPos` is being used.elementStartPos
- element start position w/ element of sizeSIZEOF_CHAR
elementCount
- element count for element of sizeSIZEOF_CHAR
- Returns:
- CharBuffer w/ native byte order as given ByteBuffer
- See Also:
slice2Float(Buffer, int, int)
-
slice2Char
public static final CharBuffer slice2Char(char[] backing, int elementStartPos, int elementCount)
Slices a primitive float backing array to a CharBuffer at the given `elementStartPos` with the given `elementCount` in short-space bywrapping
the backing array.See
slice2Float(float[], int, int)
for details.- Parameters:
backing
- source float arrayelementStartPos
- element start position w/ element of sizeSIZEOF_CHAR
elementCount
- element count for element of sizeSIZEOF_CHAR
- Returns:
- CharBuffer w/ native byte order as given ByteBuffer
- See Also:
slice2Float(float[], int, int)
-
slice2Int
public static final IntBuffer slice2Int(Buffer buf, int elementStartPos, int elementCount)
Slices a ByteBuffer or a IntBuffer to a IntBuffer at the given `elementStartPos` with the given `elementCount` in int-space.The returned sliced buffer's start position is zero.
See
slice2Float(Buffer, int, int)
for details.- Parameters:
buf
- source Buffer, maybe ByteBuffer (recommended) or IntBuffer. Buffer's position is ignored and `elementStartPos` is being used.elementStartPos
- element start position w/ element of sizeSIZEOF_INT
elementCount
- element count for element of sizeSIZEOF_INT
- Returns:
- IntBuffer w/ native byte order as given ByteBuffer
- See Also:
slice2Float(Buffer, int, int)
-
slice2Int
public static final IntBuffer slice2Int(int[] backing, int elementStartPos, int elementCount)
Slices a primitive float backing array to a IntBuffer at the given `elementStartPos` with the given `elementCount` in int-space bywrapping
the backing array.See
slice2Float(float[], int, int)
for details.- Parameters:
backing
- source float arrayelementStartPos
- element start position w/ element of sizeSIZEOF_INT
elementCount
- element count for element of sizeSIZEOF_INT
- Returns:
- IntBuffer w/ native byte order as given ByteBuffer
- See Also:
slice2Float(float[], int, int)
-
slice2Long
public static final LongBuffer slice2Long(Buffer buf, int elementStartPos, int elementCount)
Slices a ByteBuffer or a LongBuffer to a LongBuffer at the given `elementStartPos` with the given `elementCount` in long-space.The returned sliced buffer's start position is zero.
See
slice2Float(Buffer, int, int)
for details.- Parameters:
buf
- source Buffer, maybe ByteBuffer (recommended) or LongBuffer. Buffer's position is ignored and `elementStartPos` is being used.elementStartPos
- element start position w/ element of sizeSIZEOF_LONG
elementCount
- element count for element of sizeSIZEOF_LONG
- Returns:
- LongBuffer w/ native byte order as given ByteBuffer
- See Also:
slice2Float(Buffer, int, int)
-
slice2Long
public static final LongBuffer slice2Long(long[] backing, int elementStartPos, int elementCount)
Slices a primitive float backing array to a LongBuffer at the given `elementStartPos` with the given `elementCount` in long-space bywrapping
the backing array.See
slice2Float(float[], int, int)
for details.- Parameters:
backing
- source float arrayelementStartPos
- element start position w/ element of sizeSIZEOF_LONG
elementCount
- element count for element of sizeSIZEOF_LONG
- Returns:
- LongBuffer w/ native byte order as given ByteBuffer
- See Also:
slice2Float(float[], int, int)
-
slice2Double
public static final DoubleBuffer slice2Double(Buffer buf, int elementStartPos, int elementCount)
Slices a ByteBuffer or a DoubleBuffer to a DoubleBuffer at the given `elementStartPos` with the given `elementCount` in double-space.The returned sliced buffer's start position is zero.
See
slice2Float(Buffer, int, int)
for details.- Parameters:
buf
- source Buffer, maybe ByteBuffer (recommended) or DoubleBuffer. Buffer's position is ignored and `elementStartPos` is being used.elementStartPos
- element start position w/ element of sizeSIZEOF_DOUBLE
elementCount
- element count for element of sizeSIZEOF_DOUBLE
- Returns:
- DoubleBuffer w/ native byte order as given ByteBuffer
- See Also:
slice2Float(Buffer, int, int)
-
slice2Double
public static final DoubleBuffer slice2Double(double[] backing, int elementStartPos, int elementCount)
Slices a primitive float backing array to a DoubleBuffer at the given `elementStartPos` with the given `elementCount` in double-space bywrapping
the backing array.See
slice2Float(float[], int, int)
for details.- Parameters:
backing
- source float arrayelementStartPos
- element start position w/ element of sizeSIZEOF_DOUBLE
elementCount
- element count for element of sizeSIZEOF_DOUBLE
- Returns:
- DoubleBuffer w/ native byte order as given ByteBuffer
- See Also:
slice2Float(float[], int, int)
-
copyByteBuffer
public static ByteBuffer copyByteBuffer(ByteBuffer orig)
Copies the remaining elements (as defined bylimit() - position()
) in the passed ByteBuffer into a newly-allocated direct ByteBuffer. The returned buffer will have its byte order set to the host platform's native byte order. The position of the newly-allocated buffer will be zero, and the position of the passed buffer is unchanged.
-
copyFloatBuffer
public static FloatBuffer copyFloatBuffer(FloatBuffer orig)
Copies the remaining elements (as defined bylimit() - position()
) in the passed FloatBuffer into a newly-allocated direct FloatBuffer. The returned buffer will have its byte order set to the host platform's native byte order. The position of the newly-allocated buffer will be zero, and the position of the passed buffer is unchanged.
-
copyIntBuffer
public static IntBuffer copyIntBuffer(IntBuffer orig)
Copies the remaining elements (as defined bylimit() - position()
) in the passed IntBuffer into a newly-allocated direct IntBuffer. The returned buffer will have its byte order set to the host platform's native byte order. The position of the newly-allocated buffer will be zero, and the position of the passed buffer is unchanged.
-
copyShortBuffer
public static ShortBuffer copyShortBuffer(ShortBuffer orig)
Copies the remaining elements (as defined bylimit() - position()
) in the passed ShortBuffer into a newly-allocated direct ShortBuffer. The returned buffer will have its byte order set to the host platform's native byte order. The position of the newly-allocated buffer will be zero, and the position of the passed buffer is unchanged.
-
copyFloatBufferAsByteBuffer
public static ByteBuffer copyFloatBufferAsByteBuffer(FloatBuffer orig)
Copies the remaining elements (as defined bylimit() - position()
) in the passed FloatBuffer into a newly-allocated direct ByteBuffer. The returned buffer will have its byte order set to the host platform's native byte order. The position of the newly-allocated buffer will be zero, and the position of the passed buffer is unchanged.
-
copyIntBufferAsByteBuffer
public static ByteBuffer copyIntBufferAsByteBuffer(IntBuffer orig)
Copies the remaining elements (as defined bylimit() - position()
) in the passed IntBuffer into a newly-allocated direct ByteBuffer. The returned buffer will have its byte order set to the host platform's native byte order. The position of the newly-allocated buffer will be zero, and the position of the passed buffer is unchanged.
-
copyShortBufferAsByteBuffer
public static ByteBuffer copyShortBufferAsByteBuffer(ShortBuffer orig)
Copies the remaining elements (as defined bylimit() - position()
) in the passed ShortBuffer into a newly-allocated direct ByteBuffer. The returned buffer will have its byte order set to the host platform's native byte order. The position of the newly-allocated buffer will be zero, and the position of the passed buffer is unchanged.
-
getFloatArray
public static float[] getFloatArray(double[] source, int soffset, float[] dest, int doffset, int len)
- Parameters:
source
- the source arraysoffset
- the offsetdest
- the target array, if null, a new array is being created with size len.doffset
- the offset in the dest arraylen
- the payload of elements to be copied, iflen < 0
thenlen = source.length - soffset
- Returns:
- the passed or newly created target array
-
getFloatBuffer
public static FloatBuffer getFloatBuffer(DoubleBuffer source, FloatBuffer dest)
No rewind or repositioning is performed.- Parameters:
source
- the source buffer, which elements from it's current position and it's limit are being copieddest
- the target buffer, if null, a new buffer is being created with size source.remaining()- Returns:
- the passed or newly created target buffer
-
getDoubleArray
public static double[] getDoubleArray(float[] source, int soffset, double[] dest, int doffset, int len)
- Parameters:
source
- the source arraysoffset
- the offsetdest
- the target array, if null, a new array is being created with size len.doffset
- the offset in the dest arraylen
- the payload of elements to be copied, iflen < 0
thenlen = source.length - soffset
- Returns:
- the passed or newly created target array
-
getDoubleBuffer
public static DoubleBuffer getDoubleBuffer(FloatBuffer source, DoubleBuffer dest)
No rewind or repositioning is performed.- Parameters:
source
- the source buffer, which elements from it's current position and it's limit are being copieddest
- the target buffer, if null, a new buffer is being created with size source.remaining()- Returns:
- the passed or newly created target buffer
-
putb
public static <B extends Buffer> B putb(B dest, byte v)
-
put3b
public static <B extends Buffer> B put3b(B dest, byte v1, byte v2, byte v3)
-
put4b
public static <B extends Buffer> B put4b(B dest, byte v1, byte v2, byte v3, byte v4)
-
putb
public static <B extends Buffer> B putb(B dest, byte[] src, int offset, int length)
-
puts
public static <B extends Buffer> B puts(B dest, short v)
-
put3s
public static <B extends Buffer> B put3s(B dest, short v1, short v2, short v3)
-
put4s
public static <B extends Buffer> B put4s(B dest, short v1, short v2, short v3, short v4)
-
puts
public static <B extends Buffer> B puts(B dest, short[] src, int offset, int length)
-
puti
public static <B extends Buffer> B puti(B dest, int v)
-
put3i
public static <B extends Buffer> B put3i(B dest, int v1, int v2, int v3)
-
put4i
public static <B extends Buffer> B put4i(B dest, int v1, int v2, int v3, int v4)
-
puti
public static <B extends Buffer> B puti(B dest, int[] src, int offset, int length)
-
putf
public static <B extends Buffer> B putf(B dest, float v)
-
put3f
public static <B extends Buffer> B put3f(B dest, float v1, float v2, float v3)
-
put4f
public static <B extends Buffer> B put4f(B dest, float v1, float v2, float v3, float v4)
-
putf
public static <B extends Buffer> B putf(B dest, float[] src, int offset, int length)
-
putd
public static <B extends Buffer> B putd(B dest, double v)
-
put3d
public static <B extends Buffer> B put3d(B dest, double v1, double v2, double v3)
-
put4d
public static <B extends Buffer> B put4d(B dest, double v1, double v2, double v3, double v4)
-
putd
public static <B extends Buffer> B putd(B dest, double[] src, int offset, int length)
-
putNb
public static <B extends Buffer> B putNb(B dest, boolean dSigned, byte v, boolean sSigned)
Store byte source value in given buffer after normalizing it to the destination value range considering signed and unsigned source and destination representation.- Parameters:
dest
- One ofByteBuffer
,ShortBuffer
,IntBuffer
,FloatBuffer
dSigned
- true if destination buffer holds signed values, false if destination buffer holds unsigned valuesv
- source byte value to be put in dest buffersSigned
- true if source represents a signed value, false if source represents an unsigned value
-
putNs
public static <B extends Buffer> B putNs(B dest, boolean dSigned, short v, boolean sSigned)
Store short source value in given buffer after normalizing it to the destination value range considering signed and unsigned source and destination representation.- Parameters:
dest
- One ofByteBuffer
,ShortBuffer
,IntBuffer
,FloatBuffer
dSigned
- true if destination buffer holds signed values, false if destination buffer holds unsigned valuesv
- source short value to be put in dest buffersSigned
- true if source represents a signed value, false if source represents an unsigned value
-
putNi
public static <B extends Buffer> B putNi(B dest, boolean dSigned, int v, boolean sSigned)
Store short source value in given buffer after normalizing it to the destination value range considering signed and unsigned source and destination representation.- Parameters:
dest
- One ofByteBuffer
,ShortBuffer
,IntBuffer
,FloatBuffer
dSigned
- true if destination buffer holds signed values, false if destination buffer holds unsigned valuesv
- source short value to be put in dest buffersSigned
- true if source represents a signed value, false if source represents an unsigned value
-
putNf
public static <B extends Buffer> B putNf(B dest, boolean dSigned, float v)
Store float source value in given buffer after normalizing it to the destination value range considering signed and unsigned destination representation.- Parameters:
dest
- One ofByteBuffer
,ShortBuffer
,IntBuffer
,FloatBuffer
dSigned
- true if destination buffer holds signed values, false if destination buffer holds unsigned valuesv
- source float value to be put in dest buffer
-
rangeCheck
public static void rangeCheck(byte[] array, int offset, int minElementsRemaining)
-
rangeCheck
public static void rangeCheck(char[] array, int offset, int minElementsRemaining)
-
rangeCheck
public static void rangeCheck(short[] array, int offset, int minElementsRemaining)
-
rangeCheck
public static void rangeCheck(int[] array, int offset, int minElementsRemaining)
-
rangeCheck
public static void rangeCheck(long[] array, int offset, int minElementsRemaining)
-
rangeCheck
public static void rangeCheck(float[] array, int offset, int minElementsRemaining)
-
rangeCheck
public static void rangeCheck(double[] array, int offset, int minElementsRemaining)
-
rangeCheck
public static void rangeCheck(Buffer buffer, int minElementsRemaining)
-
rangeCheckBytes
public static void rangeCheckBytes(Object buffer, int minBytesRemaining) throws IllegalArgumentException, IndexOutOfBoundsException
- Parameters:
buffer
- buffer to test for minimumminBytesRemaining
- minimum bytes remaining- Throws:
IllegalArgumentException
- ifbuffer
is of invalid type.IndexOutOfBoundsException
- ifremainingBytes(Object)
is <minBytesRemaining
.
-
toString
public static StringBuilder toString(StringBuilder sb, String f, Buffer buffer)
Appends Buffer details inclusive data to a StringBuilder instance.- Parameters:
sb
- optional pass through StringBuilderf
- optional format string of one element, i.e. "%10.5f" forFloatBuffer
, seeFormatter
, ornull
for unformatted output. Note: Caller is responsible to match the format string w/ the data type as expected in the given buffer.buffer
- Any valid Buffer instance- Returns:
- the modified StringBuilder containing the Buffer details
-
copyNativeToDirectByteBuffer
public static ByteBuffer copyNativeToDirectByteBuffer(long source_address, long len)
Copy `len` native bytes @ `source_address` into a newly created directByteBuffer
.- Parameters:
source_address
- memory address of bytes to copy fromlen
- number of bytes to copy- Returns:
- newly created direct
ByteBuffer
holding the copied bytes
-
strnlen
public static int strnlen(long cstrptr, int maxlen)
Returnsstrnlen(cstrptr, maxlen)
according to POSIX.1-2008.The `strnlen()` function returns the number of bytes in the string pointed to by `cstrptr`, excluding the terminating null byte ('\0'), but at most `maxlen`. In doing this, `strnlen()` looks only at the first `maxlen` characters in the string pointed to by `cstrptr` and never beyond `cstrptr[maxlen-1]`.
-
-