com.jogamp.common.nio
Class Buffers

java.lang.Object
  extended by com.jogamp.common.nio.Buffers

public class Buffers
extends java.lang.Object

Author:
Kenneth Russel, Sven Gothel, Michael Bien

Field Summary
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
protected Buffers()
           
 
Method Summary
static java.nio.ByteBuffer copyByteBuffer(java.nio.ByteBuffer orig)
          Copies the remaining elements (as defined by limit() - position()) in the passed ByteBuffer into a newly-allocated direct ByteBuffer.
static java.nio.FloatBuffer copyFloatBuffer(java.nio.FloatBuffer orig)
          Copies the remaining elements (as defined by limit() - position()) in the passed FloatBuffer into a newly-allocated direct FloatBuffer.
static java.nio.ByteBuffer copyFloatBufferAsByteBuffer(java.nio.FloatBuffer orig)
          Copies the remaining elements (as defined by limit() - position()) in the passed FloatBuffer into a newly-allocated direct ByteBuffer.
static java.nio.IntBuffer copyIntBuffer(java.nio.IntBuffer orig)
          Copies the remaining elements (as defined by limit() - position()) in the passed IntBuffer into a newly-allocated direct IntBuffer.
static java.nio.ByteBuffer copyIntBufferAsByteBuffer(java.nio.IntBuffer orig)
          Copies the remaining elements (as defined by limit() - position()) in the passed IntBuffer into a newly-allocated direct ByteBuffer.
static java.nio.ShortBuffer copyShortBuffer(java.nio.ShortBuffer orig)
          Copies the remaining elements (as defined by limit() - position()) in the passed ShortBuffer into a newly-allocated direct ShortBuffer.
static java.nio.ByteBuffer copyShortBufferAsByteBuffer(java.nio.ShortBuffer orig)
          Copies the remaining elements (as defined by limit() - position()) in the passed ShortBuffer into a newly-allocated direct ByteBuffer.
static java.lang.Object getArray(java.lang.Object buf)
          Helper routine to return the array backing store reference from a Buffer object.
static int getDirectBufferByteOffset(java.lang.Object buf)
          Helper routine to get the Buffer byte offset by taking into account the Buffer position and the underlying type.
static java.nio.FloatBuffer getFloatBuffer(java.nio.DoubleBuffer source)
           
static int getIndirectBufferByteOffset(java.lang.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(java.lang.Object buf)
          Helper routine to tell whether a buffer is direct or not.
static java.nio.ByteBuffer nativeOrder(java.nio.ByteBuffer buf)
          Helper routine to set a ByteBuffer to the native byte order, if that operation is supported by the underlying NIO implementation.
static java.nio.ByteBuffer newDirectByteBuffer(byte[] values)
           
static java.nio.ByteBuffer newDirectByteBuffer(byte[] values, int offset)
           
static java.nio.ByteBuffer newDirectByteBuffer(byte[] values, int offset, int lenght)
           
static java.nio.ByteBuffer newDirectByteBuffer(int numElements)
          Allocates a new direct ByteBuffer with the specified number of elements.
static java.nio.CharBuffer newDirectCharBuffer(char[] values)
           
static java.nio.CharBuffer newDirectCharBuffer(char[] values, int offset)
           
static java.nio.CharBuffer newDirectCharBuffer(char[] values, int offset, int lenght)
           
static java.nio.CharBuffer newDirectCharBuffer(int numElements)
          Allocates a new direct CharBuffer with the specified number of elements.
static java.nio.DoubleBuffer newDirectDoubleBuffer(double[] values)
           
static java.nio.DoubleBuffer newDirectDoubleBuffer(double[] values, int offset)
           
static java.nio.DoubleBuffer newDirectDoubleBuffer(double[] values, int offset, int lenght)
           
static java.nio.DoubleBuffer newDirectDoubleBuffer(int numElements)
          Allocates a new direct DoubleBuffer with the specified number of elements.
static java.nio.FloatBuffer newDirectFloatBuffer(float[] values)
           
static java.nio.FloatBuffer newDirectFloatBuffer(float[] values, int offset)
           
static java.nio.FloatBuffer newDirectFloatBuffer(float[] values, int offset, int lenght)
           
static java.nio.FloatBuffer newDirectFloatBuffer(int numElements)
          Allocates a new direct FloatBuffer with the specified number of elements.
static java.nio.IntBuffer newDirectIntBuffer(int numElements)
          Allocates a new direct IntBuffer with the specified number of elements.
static java.nio.IntBuffer newDirectIntBuffer(int[] values)
           
static java.nio.IntBuffer newDirectIntBuffer(int[] values, int offset)
           
static java.nio.IntBuffer newDirectIntBuffer(int[] values, int offset, int lenght)
           
static java.nio.LongBuffer newDirectLongBuffer(int numElements)
          Allocates a new direct LongBuffer with the specified number of elements.
static java.nio.LongBuffer newDirectLongBuffer(long[] values)
           
static java.nio.LongBuffer newDirectLongBuffer(long[] values, int offset)
           
static java.nio.LongBuffer newDirectLongBuffer(long[] values, int offset, int lenght)
           
static java.nio.ShortBuffer newDirectShortBuffer(int numElements)
          Allocates a new direct ShortBuffer with the specified number of elements.
static java.nio.ShortBuffer newDirectShortBuffer(short[] values)
           
static java.nio.ShortBuffer newDirectShortBuffer(short[] values, int offset)
           
static java.nio.ShortBuffer newDirectShortBuffer(short[] values, int offset, int lenght)
           
static java.nio.Buffer put(java.nio.Buffer dest, java.nio.Buffer src)
           
static java.nio.Buffer putb(java.nio.Buffer dest, byte v)
           
static void putd(java.nio.Buffer dest, double v)
           
static void putf(java.nio.Buffer dest, float v)
           
static void puti(java.nio.Buffer dest, int v)
           
static java.nio.Buffer puts(java.nio.Buffer dest, short v)
           
static void rangeCheck(java.nio.Buffer buffer, int minElementsRemaining)
           
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 rangeCheckBytes(java.lang.Object buffer, int minBytesRemaining)
           
static int sizeOfBufferElem(java.nio.Buffer buffer)
          Returns the size of a single element of this buffer in bytes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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
Constructor Detail

Buffers

protected Buffers()
Method Detail

newDirectByteBuffer

public static java.nio.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 java.nio.ByteBuffer newDirectByteBuffer(byte[] values,
                                                      int offset,
                                                      int lenght)

newDirectByteBuffer

public static java.nio.ByteBuffer newDirectByteBuffer(byte[] values,
                                                      int offset)

newDirectByteBuffer

public static java.nio.ByteBuffer newDirectByteBuffer(byte[] values)

newDirectDoubleBuffer

public static java.nio.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 java.nio.DoubleBuffer newDirectDoubleBuffer(double[] values,
                                                          int offset,
                                                          int lenght)

newDirectDoubleBuffer

public static java.nio.DoubleBuffer newDirectDoubleBuffer(double[] values,
                                                          int offset)

newDirectDoubleBuffer

public static java.nio.DoubleBuffer newDirectDoubleBuffer(double[] values)

newDirectFloatBuffer

public static java.nio.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 java.nio.FloatBuffer newDirectFloatBuffer(float[] values,
                                                        int offset,
                                                        int lenght)

newDirectFloatBuffer

public static java.nio.FloatBuffer newDirectFloatBuffer(float[] values,
                                                        int offset)

newDirectFloatBuffer

public static java.nio.FloatBuffer newDirectFloatBuffer(float[] values)

newDirectIntBuffer

public static java.nio.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 java.nio.IntBuffer newDirectIntBuffer(int[] values,
                                                    int offset,
                                                    int lenght)

newDirectIntBuffer

public static java.nio.IntBuffer newDirectIntBuffer(int[] values,
                                                    int offset)

newDirectIntBuffer

public static java.nio.IntBuffer newDirectIntBuffer(int[] values)

newDirectLongBuffer

public static java.nio.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 java.nio.LongBuffer newDirectLongBuffer(long[] values,
                                                      int offset,
                                                      int lenght)

newDirectLongBuffer

public static java.nio.LongBuffer newDirectLongBuffer(long[] values,
                                                      int offset)

newDirectLongBuffer

public static java.nio.LongBuffer newDirectLongBuffer(long[] values)

newDirectShortBuffer

public static java.nio.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 java.nio.ShortBuffer newDirectShortBuffer(short[] values,
                                                        int offset,
                                                        int lenght)

newDirectShortBuffer

public static java.nio.ShortBuffer newDirectShortBuffer(short[] values,
                                                        int offset)

newDirectShortBuffer

public static java.nio.ShortBuffer newDirectShortBuffer(short[] values)

newDirectCharBuffer

public static java.nio.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 java.nio.CharBuffer newDirectCharBuffer(char[] values,
                                                      int offset,
                                                      int lenght)

newDirectCharBuffer

public static java.nio.CharBuffer newDirectCharBuffer(char[] values,
                                                      int offset)

newDirectCharBuffer

public static java.nio.CharBuffer newDirectCharBuffer(char[] values)

nativeOrder

public static java.nio.ByteBuffer nativeOrder(java.nio.ByteBuffer buf)
Helper routine to set a ByteBuffer to the native byte order, if that operation is supported by the underlying NIO implementation.


sizeOfBufferElem

public static final int sizeOfBufferElem(java.nio.Buffer buffer)
Returns the size of a single element of this buffer in bytes.


isDirect

public static boolean isDirect(java.lang.Object buf)
Helper routine to tell whether a buffer is direct or not. Null pointers are considered NOT direct. isDirect() should really be public in Buffer and not replicated in all subclasses.


getDirectBufferByteOffset

public static int getDirectBufferByteOffset(java.lang.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 java.lang.Object getArray(java.lang.Object buf)
Helper routine to return the array backing store reference from a Buffer object.


getIndirectBufferByteOffset

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


copyByteBuffer

public static java.nio.ByteBuffer copyByteBuffer(java.nio.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 (though its mark is changed).


copyFloatBuffer

public static java.nio.FloatBuffer copyFloatBuffer(java.nio.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 (though its mark is changed).


copyIntBuffer

public static java.nio.IntBuffer copyIntBuffer(java.nio.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 (though its mark is changed).


copyShortBuffer

public static java.nio.ShortBuffer copyShortBuffer(java.nio.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 (though its mark is changed).


copyFloatBufferAsByteBuffer

public static java.nio.ByteBuffer copyFloatBufferAsByteBuffer(java.nio.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 (though its mark is changed).


copyIntBufferAsByteBuffer

public static java.nio.ByteBuffer copyIntBufferAsByteBuffer(java.nio.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 (though its mark is changed).


copyShortBufferAsByteBuffer

public static java.nio.ByteBuffer copyShortBufferAsByteBuffer(java.nio.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 (though its mark is changed).


getFloatBuffer

public static final java.nio.FloatBuffer getFloatBuffer(java.nio.DoubleBuffer source)

put

public static java.nio.Buffer put(java.nio.Buffer dest,
                                  java.nio.Buffer src)

putb

public static java.nio.Buffer putb(java.nio.Buffer dest,
                                   byte v)

puts

public static java.nio.Buffer puts(java.nio.Buffer dest,
                                   short v)

puti

public static void puti(java.nio.Buffer dest,
                        int v)

putf

public static void putf(java.nio.Buffer dest,
                        float v)

putd

public static void putd(java.nio.Buffer dest,
                        double v)

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(java.nio.Buffer buffer,
                              int minElementsRemaining)

rangeCheckBytes

public static void rangeCheckBytes(java.lang.Object buffer,
                                   int minBytesRemaining)