Top Description Fields Constructors Methods
com.jogamp.common.nio

public Class Buffers

extends Object
Class Inheritance
Imports
java.nio.Buffer, .ByteBuffer, .ByteOrder, .CharBuffer, .DoubleBuffer, .FloatBuffer, .IntBuffer, .LongBuffer, .ShortBuffer, com.jogamp.common.util.ValueConv

Utility methods allowing easy java.nio.Buffer manipulations.
Authors
Kenneth Russel, Sven Gothel, Michael Bien

Field Summary

Modifier and TypeField and Description
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public static ByteBuffer
copyByteBuffer(final ByteBuffer orig)

Copies the remaining elements (as defined by limit() - position()) in the passed ByteBuffer into a newly-allocated direct ByteBuffer.

public static FloatBuffer
copyFloatBuffer(final FloatBuffer orig)

Copies the remaining elements (as defined by limit() - position()) in the passed FloatBuffer into a newly-allocated direct FloatBuffer.

public static ByteBuffer
copyFloatBufferAsByteBuffer(final FloatBuffer orig)

Copies the remaining elements (as defined by limit() - position()) in the passed FloatBuffer into a newly-allocated direct ByteBuffer.

public static IntBuffer
copyIntBuffer(final IntBuffer orig)

Copies the remaining elements (as defined by limit() - position()) in the passed IntBuffer into a newly-allocated direct IntBuffer.

public static ByteBuffer
copyIntBufferAsByteBuffer(final IntBuffer orig)

Copies the remaining elements (as defined by limit() - position()) in the passed IntBuffer into a newly-allocated direct ByteBuffer.

public static ShortBuffer
copyShortBuffer(final ShortBuffer orig)

Copies the remaining elements (as defined by limit() - position()) in the passed ShortBuffer into a newly-allocated direct ShortBuffer.

public static ByteBuffer
copyShortBufferAsByteBuffer(final ShortBuffer orig)

Copies the remaining elements (as defined by limit() - position()) in the passed ShortBuffer into a newly-allocated direct ByteBuffer.

public static Object
getArray(final Object buf)

Helper routine to return the array backing store reference from a Buffer object.

public static int
getDirectBufferByteOffset(final Object buf)

Helper routine to get the Buffer byte offset by taking into account the Buffer position and the underlying type.

public static double[]

Returns:

the passed or newly created target array
getDoubleArray
(final float[]
the source array
source
,
final int
the offset
soffset
,
double[]
the target array, if null, a new array is being created with size len.
dest
,
int
the offset in the dest array
doffset
,
int
the payload of elements to be copied, if len < 0 then len = source.length - soffset
len
)

public static DoubleBuffer

Returns:

the passed or newly created target buffer
getDoubleBuffer
(final FloatBuffer
the source buffer, which elements from it's current position and it's limit are being copied
source
,
DoubleBuffer
the target buffer, if null, a new buffer is being created with size source.remaining()
dest
)

No rewind or repositioning is performed.

public static float[]

Returns:

the passed or newly created target array
getFloatArray
(final double[]
the source array
source
,
final int
the offset
soffset
,
float[]
the target array, if null, a new array is being created with size len.
dest
,
int
the offset in the dest array
doffset
,
int
the payload of elements to be copied, if len < 0 then len = source.length - soffset
len
)

public static FloatBuffer

Returns:

the passed or newly created target buffer
getFloatBuffer
(final DoubleBuffer
the source buffer, which elements from it's current position and it's limit are being copied
source
,
FloatBuffer
the target buffer, if null, a new buffer is being created with size source.remaining()
dest
)

No rewind or repositioning is performed.

public static int
getIndirectBufferByteOffset(final 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.

public static boolean
isDirect(final Object buf)

Helper routine to tell whether a buffer is direct or not.

public static ByteBuffer
nativeOrder(final ByteBuffer buf)

Helper routine to set a ByteBuffer to the native byte order, if that operation is supported by the underlying NIO implementation.

public static ByteBuffer
newDirectByteBuffer(final int numElements)

Allocates a new direct ByteBuffer with the specified number of elements.

public static ByteBuffer
newDirectByteBuffer(final byte[] values, final int offset, final int length)

public static ByteBuffer
newDirectByteBuffer(final byte[] values, final int offset)

public static ByteBuffer
newDirectByteBuffer(final byte[] values)

public static CharBuffer
newDirectCharBuffer(final int numElements)

Allocates a new direct CharBuffer with the specified number of elements.

public static CharBuffer
newDirectCharBuffer(final char[] values, final int offset, final int length)

public static CharBuffer
newDirectCharBuffer(final char[] values, final int offset)

public static CharBuffer
newDirectCharBuffer(final char[] values)

public static DoubleBuffer
newDirectDoubleBuffer(final int numElements)

Allocates a new direct DoubleBuffer with the specified number of elements.

public static DoubleBuffer
newDirectDoubleBuffer(final double[] values, final int offset, final int length)

public static DoubleBuffer
newDirectDoubleBuffer(final double[] values, final int offset)

public static DoubleBuffer
newDirectDoubleBuffer(final double[] values)

public static FloatBuffer
newDirectFloatBuffer(final int numElements)

Allocates a new direct FloatBuffer with the specified number of elements.

public static FloatBuffer
newDirectFloatBuffer(final float[] values, final int offset, final int length)

public static FloatBuffer
newDirectFloatBuffer(final float[] values, final int offset)

public static FloatBuffer
newDirectFloatBuffer(final float[] values)

public static IntBuffer
newDirectIntBuffer(final int numElements)

Allocates a new direct IntBuffer with the specified number of elements.

public static IntBuffer
newDirectIntBuffer(final int[] values, final int offset, final int length)

public static IntBuffer
newDirectIntBuffer(final int[] values, final int offset)

public static IntBuffer
newDirectIntBuffer(final int[] values)

public static LongBuffer
newDirectLongBuffer(final int numElements)

Allocates a new direct LongBuffer with the specified number of elements.

public static LongBuffer
newDirectLongBuffer(final long[] values, final int offset, final int length)

public static LongBuffer
newDirectLongBuffer(final long[] values, final int offset)

public static LongBuffer
newDirectLongBuffer(final long[] values)

public static ShortBuffer
newDirectShortBuffer(final int numElements)

Allocates a new direct ShortBuffer with the specified number of elements.

public static ShortBuffer
newDirectShortBuffer(final short[] values, final int offset, final int length)

public static ShortBuffer
newDirectShortBuffer(final short[] values, final int offset)

public static ShortBuffer
newDirectShortBuffer(final short[] values)

public static <B extends Buffer> B
put(final B dest, final Buffer src)

public static <B extends Buffer> B
putb(final B dest, final byte v)

public static <B extends Buffer> B
putd(final B dest, final double v)

public static <B extends Buffer> B
putf(final B dest, final float v)

public static <B extends Buffer> B
puti(final B dest, final int v)

public static <B extends Buffer> B
putNb(final B dest, final boolean
true if destination buffer holds signed values, false if destination buffer holds unsigned values
dSigned
,
final byte
source byte value to be put in dest buffer
v
,
final boolean
true if source represents a signed value, false if source represents an unsigned value
sSigned
)

Store byte source value in given buffer after normalizing it to the destination value range considering signed and unsigned source and destination representation.

public static <B extends Buffer> B
putNf(final B dest, final boolean
true if destination buffer holds signed values, false if destination buffer holds unsigned values
dSigned
,
final float
source float value to be put in dest buffer
v
)

Store float source value in given buffer after normalizing it to the destination value range considering signed and unsigned destination representation.

public static <B extends Buffer> B
putNi(final B dest, final boolean
true if destination buffer holds signed values, false if destination buffer holds unsigned values
dSigned
,
final int
source short value to be put in dest buffer
v
,
final boolean
true if source represents a signed value, false if source represents an unsigned value
sSigned
)

Store short source value in given buffer after normalizing it to the destination value range considering signed and unsigned source and destination representation.

public static <B extends Buffer> B
putNs(final B dest, final boolean
true if destination buffer holds signed values, false if destination buffer holds unsigned values
dSigned
,
final short
source short value to be put in dest buffer
v
,
final boolean
true if source represents a signed value, false if source represents an unsigned value
sSigned
)

Store short source value in given buffer after normalizing it to the destination value range considering signed and unsigned source and destination representation.

public static <B extends Buffer> B
puts(final B dest, final short v)

public static void
rangeCheck(final byte[] array, final int offset, final int minElementsRemaining)

public static void
rangeCheck(final char[] array, final int offset, final int minElementsRemaining)

public static void
rangeCheck(final short[] array, final int offset, final int minElementsRemaining)

public static void
rangeCheck(final int[] array, final int offset, final int minElementsRemaining)

public static void
rangeCheck(final long[] array, final int offset, final int minElementsRemaining)

public static void
rangeCheck(final float[] array, final int offset, final int minElementsRemaining)

public static void
rangeCheck(final double[] array, final int offset, final int minElementsRemaining)

public static void
rangeCheck(final Buffer buffer, final int minElementsRemaining)

public static void
rangeCheckBytes(final Object
buffer to test for minimum
buffer
,
final int
minimum bytes remaining
minBytesRemaining
)

public static int

Returns:

If buffer is null, returns 0, otherwise the remaining size in bytes.
remainingBytes
(final Object
Anonymous Buffer of type NativeBuffer or a derivation of Buffer.
buffer
)

Returns the number of remaining bytes of the given anonymous buffer.

public static int

Returns:

If buffer is null, returns 0, otherwise the remaining size in elements.
remainingElem
(final Object
Anonymous Buffer of type NativeBuffer or a derivation of Buffer.
buffer
)

Returns the number of remaining elements of the given anonymous buffer.

public static int
sizeOfBufferElem(final Object buffer)

Returns the size of a single element of the given buffer in bytes or 0 if the given buffer is null.

public static <B extends Buffer> B
slice(final B buffer)

Calls slice on the specified buffer while maintaining the byteorder.

public static <B extends Buffer> B
slice(final B buffer, final int offset, final int size)

Slices the specified buffer with offset as position and offset+size as limit while maintaining the byteorder.

public static final FloatBuffer

Returns:

FloatBuffer w/ native byte order as given ByteBuffer
slice2Float
(final Buffer
source Buffer, maybe ByteBuffer (recommended) or FloatBuffer. Buffer's position is ignored and floatPos is being used.
buf
,
final int floatStartPos, final int floatSize)

Slices a ByteBuffer or a FloatBuffer to a FloatBuffer at the given position with the given size in float-space.

public static final FloatBuffer

Returns:

FloatBuffer w/ native byte order as given ByteBuffer
slice2Float
(final float[]
source float array
backing
,
final int floatStartPos, final int floatSize)

Slices a primitive float backing array to a FloatBuffer at the given position with the given size in float-space by wrapping the backing array.

public static StringBuilder

Returns:

the modified StringBuilder containing the Buffer details
toString
(StringBuilder
optional pass through StringBuilder
sb
,
final String
optional format string of one element, i.e. "%10.5f" for FloatBuffer, see java.util.Formatter, or null for unformatted output

Note

Caller is responsible to match the format string w/ the data type as expected in the given buffer.

f
,
final Buffer
Any valid Buffer instance
buffer
)

Appends Buffer details inclusive data to a StringBuilder instance.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

SIZEOF_BYTEback to summary
public static final int SIZEOF_BYTE
SIZEOF_CHARback to summary
public static final int SIZEOF_CHAR
SIZEOF_DOUBLEback to summary
public static final int SIZEOF_DOUBLE
SIZEOF_FLOATback to summary
public static final int SIZEOF_FLOAT
SIZEOF_INTback to summary
public static final int SIZEOF_INT
SIZEOF_LONGback to summary
public static final int SIZEOF_LONG
SIZEOF_SHORTback to summary
public static final int SIZEOF_SHORT

Constructor Detail

Buffersback to summary
protected Buffers()

Method Detail

copyByteBufferback to summary
public static ByteBuffer copyByteBuffer(final ByteBuffer orig)

Copies the remaining elements (as defined by limit() - 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.

copyFloatBufferback to summary
public static FloatBuffer copyFloatBuffer(final FloatBuffer orig)

Copies the remaining elements (as defined by limit() - 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.

copyFloatBufferAsByteBufferback to summary
public static ByteBuffer copyFloatBufferAsByteBuffer(final FloatBuffer orig)

Copies the remaining elements (as defined by limit() - 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.

copyIntBufferback to summary
public static IntBuffer copyIntBuffer(final IntBuffer orig)

Copies the remaining elements (as defined by limit() - 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.

copyIntBufferAsByteBufferback to summary
public static ByteBuffer copyIntBufferAsByteBuffer(final IntBuffer orig)

Copies the remaining elements (as defined by limit() - 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.

copyShortBufferback to summary
public static ShortBuffer copyShortBuffer(final ShortBuffer orig)

Copies the remaining elements (as defined by limit() - 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.

copyShortBufferAsByteBufferback to summary
public static ByteBuffer copyShortBufferAsByteBuffer(final ShortBuffer orig)

Copies the remaining elements (as defined by limit() - 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.

getArrayback to summary
public static Object getArray(final Object buf) throws UnsupportedOperationException, IllegalArgumentException

Helper routine to return the array backing store reference from a Buffer object.

Exceptions
UnsupportedOperationException:
if the passed Object does not have an array backing store
IllegalArgumentException:
if the passed Object is neither of type java.nio.Buffer or NativeBuffer.
getDirectBufferByteOffsetback to summary
public static int getDirectBufferByteOffset(final 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.

getDoubleArrayback to summary
public static double[] getDoubleArray(final float[] source, final int soffset, double[] dest, int doffset, int len)
Parameters
source:float[]

the source array

soffset:int

the offset

dest:double[]

the target array, if null, a new array is being created with size len.

doffset:int

the offset in the dest array

len:int

the payload of elements to be copied, if len < 0 then len = source.length - soffset

Returns:double[]

the passed or newly created target array

getDoubleBufferback to summary
public static DoubleBuffer getDoubleBuffer(final FloatBuffer source, DoubleBuffer dest)

No rewind or repositioning is performed.

Parameters
source:FloatBuffer

the source buffer, which elements from it's current position and it's limit are being copied

dest:DoubleBuffer

the target buffer, if null, a new buffer is being created with size source.remaining()

Returns:DoubleBuffer

the passed or newly created target buffer

getFloatArrayback to summary
public static float[] getFloatArray(final double[] source, final int soffset, float[] dest, int doffset, int len)
Parameters
source:double[]

the source array

soffset:int

the offset

dest:float[]

the target array, if null, a new array is being created with size len.

doffset:int

the offset in the dest array

len:int

the payload of elements to be copied, if len < 0 then len = source.length - soffset

Returns:float[]

the passed or newly created target array

getFloatBufferback to summary
public static FloatBuffer getFloatBuffer(final DoubleBuffer source, FloatBuffer dest)

No rewind or repositioning is performed.

Parameters
source:DoubleBuffer

the source buffer, which elements from it's current position and it's limit are being copied

dest:FloatBuffer

the target buffer, if null, a new buffer is being created with size source.remaining()

Returns:FloatBuffer

the passed or newly created target buffer

getIndirectBufferByteOffsetback to summary
public static int getIndirectBufferByteOffset(final 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.

isDirectback to summary
public static boolean isDirect(final Object buf)

Helper routine to tell whether a buffer is direct or not. Null pointers are considered direct.

nativeOrderback to summary
public static ByteBuffer nativeOrder(final ByteBuffer buf)

Helper routine to set a ByteBuffer to the native byte order, if that operation is supported by the underlying NIO implementation.

newDirectByteBufferback to summary
public static ByteBuffer newDirectByteBuffer(final 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.

newDirectByteBufferback to summary
public static ByteBuffer newDirectByteBuffer(final byte[] values, final int offset, final int length)
newDirectByteBufferback to summary
public static ByteBuffer newDirectByteBuffer(final byte[] values, final int offset)
newDirectByteBufferback to summary
public static ByteBuffer newDirectByteBuffer(final byte[] values)
newDirectCharBufferback to summary
public static CharBuffer newDirectCharBuffer(final 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.

newDirectCharBufferback to summary
public static CharBuffer newDirectCharBuffer(final char[] values, final int offset, final int length)
newDirectCharBufferback to summary
public static CharBuffer newDirectCharBuffer(final char[] values, final int offset)
newDirectCharBufferback to summary
public static CharBuffer newDirectCharBuffer(final char[] values)
newDirectDoubleBufferback to summary
public static DoubleBuffer newDirectDoubleBuffer(final 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.

newDirectDoubleBufferback to summary
public static DoubleBuffer newDirectDoubleBuffer(final double[] values, final int offset, final int length)
newDirectDoubleBufferback to summary
public static DoubleBuffer newDirectDoubleBuffer(final double[] values, final int offset)
newDirectDoubleBufferback to summary
public static DoubleBuffer newDirectDoubleBuffer(final double[] values)
newDirectFloatBufferback to summary
public static FloatBuffer newDirectFloatBuffer(final 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.

newDirectFloatBufferback to summary
public static FloatBuffer newDirectFloatBuffer(final float[] values, final int offset, final int length)
newDirectFloatBufferback to summary
public static FloatBuffer newDirectFloatBuffer(final float[] values, final int offset)
newDirectFloatBufferback to summary
public static FloatBuffer newDirectFloatBuffer(final float[] values)
newDirectIntBufferback to summary
public static IntBuffer newDirectIntBuffer(final 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.

newDirectIntBufferback to summary
public static IntBuffer newDirectIntBuffer(final int[] values, final int offset, final int length)
newDirectIntBufferback to summary
public static IntBuffer newDirectIntBuffer(final int[] values, final int offset)
newDirectIntBufferback to summary
public static IntBuffer newDirectIntBuffer(final int[] values)
newDirectLongBufferback to summary
public static LongBuffer newDirectLongBuffer(final 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.

newDirectLongBufferback to summary
public static LongBuffer newDirectLongBuffer(final long[] values, final int offset, final int length)
newDirectLongBufferback to summary
public static LongBuffer newDirectLongBuffer(final long[] values, final int offset)
newDirectLongBufferback to summary
public static LongBuffer newDirectLongBuffer(final long[] values)
newDirectShortBufferback to summary
public static ShortBuffer newDirectShortBuffer(final 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.

newDirectShortBufferback to summary
public static ShortBuffer newDirectShortBuffer(final short[] values, final int offset, final int length)
newDirectShortBufferback to summary
public static ShortBuffer newDirectShortBuffer(final short[] values, final int offset)
newDirectShortBufferback to summary
public static ShortBuffer newDirectShortBuffer(final short[] values)
putback to summary
public static <B extends Buffer> B put(final B dest, final Buffer src)
Annotations
@SuppressWarnings:unchecked
putbback to summary
public static <B extends Buffer> B putb(final B dest, final byte v)
Annotations
@SuppressWarnings:unchecked
putdback to summary
public static <B extends Buffer> B putd(final B dest, final double v)
Annotations
@SuppressWarnings:unchecked
putfback to summary
public static <B extends Buffer> B putf(final B dest, final float v)
Annotations
@SuppressWarnings:unchecked
putiback to summary
public static <B extends Buffer> B puti(final B dest, final int v)
Annotations
@SuppressWarnings:unchecked
putNbback to summary
public static <B extends Buffer> B putNb(final B dest, final boolean dSigned, final byte v, final 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:B

One of ByteBuffer, ShortBuffer, IntBuffer, FloatBuffer

dSigned:boolean

true if destination buffer holds signed values, false if destination buffer holds unsigned values

v:byte

source byte value to be put in dest buffer

sSigned:boolean

true if source represents a signed value, false if source represents an unsigned value

Annotations
@SuppressWarnings:unchecked
putNfback to summary
public static <B extends Buffer> B putNf(final B dest, final boolean dSigned, final 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:B

One of ByteBuffer, ShortBuffer, IntBuffer, FloatBuffer

dSigned:boolean

true if destination buffer holds signed values, false if destination buffer holds unsigned values

v:float

source float value to be put in dest buffer

Annotations
@SuppressWarnings:unchecked
putNiback to summary
public static <B extends Buffer> B putNi(final B dest, final boolean dSigned, final int v, final 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:B

One of ByteBuffer, ShortBuffer, IntBuffer, FloatBuffer

dSigned:boolean

true if destination buffer holds signed values, false if destination buffer holds unsigned values

v:int

source short value to be put in dest buffer

sSigned:boolean

true if source represents a signed value, false if source represents an unsigned value

Annotations
@SuppressWarnings:unchecked
putNsback to summary
public static <B extends Buffer> B putNs(final B dest, final boolean dSigned, final short v, final 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:B

One of ByteBuffer, ShortBuffer, IntBuffer, FloatBuffer

dSigned:boolean

true if destination buffer holds signed values, false if destination buffer holds unsigned values

v:short

source short value to be put in dest buffer

sSigned:boolean

true if source represents a signed value, false if source represents an unsigned value

Annotations
@SuppressWarnings:unchecked
putsback to summary
public static <B extends Buffer> B puts(final B dest, final short v)
Annotations
@SuppressWarnings:unchecked
rangeCheckback to summary
public static void rangeCheck(final byte[] array, final int offset, final int minElementsRemaining)
rangeCheckback to summary
public static void rangeCheck(final char[] array, final int offset, final int minElementsRemaining)
rangeCheckback to summary
public static void rangeCheck(final short[] array, final int offset, final int minElementsRemaining)
rangeCheckback to summary
public static void rangeCheck(final int[] array, final int offset, final int minElementsRemaining)
rangeCheckback to summary
public static void rangeCheck(final long[] array, final int offset, final int minElementsRemaining)
rangeCheckback to summary
public static void rangeCheck(final float[] array, final int offset, final int minElementsRemaining)
rangeCheckback to summary
public static void rangeCheck(final double[] array, final int offset, final int minElementsRemaining)
rangeCheckback to summary
public static void rangeCheck(final Buffer buffer, final int minElementsRemaining)
rangeCheckBytesback to summary
public static void rangeCheckBytes(final Object buffer, final int minBytesRemaining) throws IllegalArgumentException, IndexOutOfBoundsException
Parameters
buffer:Object

buffer to test for minimum

minBytesRemaining:int

minimum bytes remaining

Exceptions
IllegalArgumentException:
if buffer is of invalid type.
IndexOutOfBoundsException:
if remainingBytes(Object) is < minBytesRemaining.
remainingBytesback to summary
public static int remainingBytes(final Object buffer) throws IllegalArgumentException

Returns the number of remaining bytes of the given anonymous buffer.

Parameters
buffer:Object

Anonymous Buffer of type NativeBuffer or a derivation of Buffer.

Returns:int

If buffer is null, returns 0, otherwise the remaining size in bytes.

Exceptions
IllegalArgumentException:
if buffer is of invalid type.
remainingElemback to summary
public static int remainingElem(final Object buffer) throws IllegalArgumentException

Returns the number of remaining elements of the given anonymous buffer.

Parameters
buffer:Object

Anonymous Buffer of type NativeBuffer or a derivation of Buffer.

Returns:int

If buffer is null, returns 0, otherwise the remaining size in elements.

Exceptions
IllegalArgumentException:
if buffer is of invalid type.
sizeOfBufferElemback to summary
public static int sizeOfBufferElem(final Object buffer)

Returns the size of a single element of the given buffer in bytes or 0 if the given buffer is null.

sliceback to summary
public static <B extends Buffer> B slice(final B buffer)

Calls slice on the specified buffer while maintaining the byteorder.

Annotations
@SuppressWarnings:unchecked
See Also
slice(java.nio.Buffer, int, int)
sliceback to summary
public static <B extends Buffer> B slice(final B buffer, final int offset, final 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.

slice2Floatback to summary
public static final FloatBuffer slice2Float(final Buffer buf, final int floatStartPos, final int floatSize)

Slices a ByteBuffer or a FloatBuffer to a FloatBuffer at the given position with the given size in float-space.

The returned sliced buffer's start position is always zero.

The returned sliced buffer is marked at it's start position. Hence FloatBuffer#reset() will rewind it to start after applying relative operations like FloatBuffer#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:Buffer

source Buffer, maybe ByteBuffer (recommended) or FloatBuffer. Buffer's position is ignored and floatPos is being used.

floatStartPos:int

Buffers#SIZEOF_FLOAT position

floatSize:int

Buffers#SIZEOF_FLOAT size

Returns:FloatBuffer

FloatBuffer w/ native byte order as given ByteBuffer

slice2Floatback to summary
public static final FloatBuffer slice2Float(final float[] backing, final int floatStartPos, final int floatSize)

Slices a primitive float backing array to a FloatBuffer at the given position with the given size in float-space by wrapping the backing array.

Due to wrapping the backing array, the returned sliced buffer's start position equals the given floatStartPos within the given backing array while it's array-offset is zero. This has the advantage of being able to dismiss the array-offset in user code, while only being required to consider it's position.

The returned sliced buffer is marked at it's start position. Hence FloatBuffer#reset() will rewind it to start after applying relative operations like FloatBuffer#get().

Parameters
backing:float[]

source float array

floatStartPos:int

Buffers#SIZEOF_FLOAT position

floatSize:int

Buffers#SIZEOF_FLOAT size

Returns:FloatBuffer

FloatBuffer w/ native byte order as given ByteBuffer

toStringback to summary
public static StringBuilder toString(StringBuilder sb, final String f, final Buffer buffer)

Appends Buffer details inclusive data to a StringBuilder instance.

Parameters
sb:StringBuilder

optional pass through StringBuilder

f:String

optional format string of one element, i.e. "%10.5f" for FloatBuffer, see java.util.Formatter, or null for unformatted output

Note

Caller is responsible to match the format string w/ the data type as expected in the given buffer.

buffer:Buffer

Any valid Buffer instance

Returns:StringBuilder

the modified StringBuilder containing the Buffer details