org.jagatoo.util.nio
Class BufferUtils

java.lang.Object
  extended by org.jagatoo.util.nio.BufferUtils

public final class BufferUtils
extends java.lang.Object

Some often-used Buffer code for creating native buffers of the appropriate size.


Constructor Summary
BufferUtils()
           
 
Method Summary
static java.nio.ByteBuffer createByteBuffer(byte... values)
          Constructs a direct native-ordered bytebuffer with the specified size.
static java.nio.ByteBuffer createByteBuffer(int size)
          Constructs a direct native-ordered bytebuffer with the specified size.
static java.nio.CharBuffer createCharBuffer(char... values)
          Constructs a direct native-order charbuffer with the specified number of elements.
static java.nio.CharBuffer createCharBuffer(int size)
          Constructs a direct native-order charbuffer with the specified number of elements.
static java.nio.DoubleBuffer createDoubleBuffer(double... values)
          Constructs a direct native-order doublebuffer with the specified number of elements.
static java.nio.DoubleBuffer createDoubleBuffer(int size)
          Constructs a direct native-order doublebuffer with the specified number of elements.
static java.nio.FloatBuffer createFloatBuffer(float... values)
          Constructs a direct native-order floatbuffer with the specified number of elements.
static java.nio.FloatBuffer createFloatBuffer(int size)
          Constructs a direct native-order floatbuffer with the specified number of elements.
static java.nio.IntBuffer createIntBuffer(int... values)
          Constructs a direct native-order intbuffer with the specified number of elements.
static java.nio.IntBuffer createIntBuffer(int size)
          Constructs a direct native-order intbuffer with the specified number of elements.
static java.nio.LongBuffer createLongBuffer(int size)
          Constructs a direct native-order longbuffer with the specified number of elements.
static java.nio.LongBuffer createLongBuffer(long... values)
          Constructs a direct native-order longbuffer with the specified number of elements.
static java.nio.ShortBuffer createShortBuffer(int size)
          Constructs a direct native-order shortbuffer with the specified number of elements.
static java.nio.ShortBuffer createShortBuffer(short... values)
          Constructs a direct native-order shortbuffer with the specified number of elements.
static int getElementSizeExponent(java.nio.Buffer buf)
           
static int getOffset(java.nio.Buffer buffer)
          A helper function, which is used to get the byte offset in an arbitrary buffer based on its position
static boolean getUseDirectBuffers()
          Gets whether to generally create direct buffers, if true, non-direct buffers otherwise.
static void setUseDirectBuffers(boolean b)
          Sets whether to generally create direct buffers, if true, non-direct buffers otherwise.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BufferUtils

public BufferUtils()
Method Detail

setUseDirectBuffers

public static void setUseDirectBuffers(boolean b)
Sets whether to generally create direct buffers, if true, non-direct buffers otherwise.

Parameters:
b -

getUseDirectBuffers

public static final boolean getUseDirectBuffers()
Gets whether to generally create direct buffers, if true, non-direct buffers otherwise.

Returns:
whether to generally create direct buffers, if true, non-direct buffers otherwise.

createByteBuffer

public static java.nio.ByteBuffer createByteBuffer(int size)
Constructs a direct native-ordered bytebuffer with the specified size.

Parameters:
size - The size, in bytes
Returns:
a ByteBuffer

createByteBuffer

public static java.nio.ByteBuffer createByteBuffer(byte... values)
Constructs a direct native-ordered bytebuffer with the specified size.

Parameters:
values - the values
Returns:
a ByteBuffer

createShortBuffer

public static java.nio.ShortBuffer createShortBuffer(int size)
Constructs a direct native-order shortbuffer with the specified number of elements.

Parameters:
size - The size, in shorts
Returns:
a ShortBuffer

createShortBuffer

public static java.nio.ShortBuffer createShortBuffer(short... values)
Constructs a direct native-order shortbuffer with the specified number of elements.

Parameters:
values - the values
Returns:
a ShortBuffer

createCharBuffer

public static java.nio.CharBuffer createCharBuffer(int size)
Constructs a direct native-order charbuffer with the specified number of elements.

Parameters:
size - The size, in chars
Returns:
a CharBuffer

createCharBuffer

public static java.nio.CharBuffer createCharBuffer(char... values)
Constructs a direct native-order charbuffer with the specified number of elements.

Parameters:
values - the values
Returns:
a CharBuffer

createIntBuffer

public static java.nio.IntBuffer createIntBuffer(int size)
Constructs a direct native-order intbuffer with the specified number of elements.

Parameters:
size - The size, in ints
Returns:
an IntBuffer

createIntBuffer

public static java.nio.IntBuffer createIntBuffer(int... values)
Constructs a direct native-order intbuffer with the specified number of elements.

Parameters:
values - the values
Returns:
an IntBuffer

createLongBuffer

public static java.nio.LongBuffer createLongBuffer(int size)
Constructs a direct native-order longbuffer with the specified number of elements.

Parameters:
size - The size, in longs
Returns:
a LongBuffer

createLongBuffer

public static java.nio.LongBuffer createLongBuffer(long... values)
Constructs a direct native-order longbuffer with the specified number of elements.

Parameters:
values - the values
Returns:
a LongBuffer

createFloatBuffer

public static java.nio.FloatBuffer createFloatBuffer(int size)
Constructs a direct native-order floatbuffer with the specified number of elements.

Parameters:
size - The size, in floats
Returns:
a FloatBuffer

createFloatBuffer

public static java.nio.FloatBuffer createFloatBuffer(float... values)
Constructs a direct native-order floatbuffer with the specified number of elements.

Parameters:
values - the values
Returns:
a FloatBuffer

createDoubleBuffer

public static java.nio.DoubleBuffer createDoubleBuffer(int size)
Constructs a direct native-order doublebuffer with the specified number of elements.

Parameters:
size - The size, in floats
Returns:
a FloatBuffer

createDoubleBuffer

public static java.nio.DoubleBuffer createDoubleBuffer(double... values)
Constructs a direct native-order doublebuffer with the specified number of elements.

Parameters:
values - the values
Returns:
a FloatBuffer

getElementSizeExponent

public static int getElementSizeExponent(java.nio.Buffer buf)
Returns:
n, where buffer_element_size=2^n.

getOffset

public static int getOffset(java.nio.Buffer buffer)
A helper function, which is used to get the byte offset in an arbitrary buffer based on its position

Returns:
the position of the buffer, in BYTES