hmi.graphics.util
Class BufferUtil

java.lang.Object
  extended by hmi.graphics.util.BufferUtil

public final class BufferUtil
extends Object

Some utils for allocating direct NIO buffers.

Author:
Job Zwiers

Field Summary
static int SIZEOF_BYTE
           
static int SIZEOF_DOUBLE
           
static int SIZEOF_FLOAT
           
static int SIZEOF_INT
           
static int SIZEOF_LONG
           
static int SIZEOF_SHORT
           
 
Constructor Summary
private BufferUtil()
           
 
Method Summary
static ByteBuffer byteBuffer(byte[] a)
          Converts an byte array into a direct ByteBuffer.
static ByteBuffer byteBuffer(String s)
          Converts a String into a direct ByteBuffer.
static ByteBuffer directByteBuffer(int numElements)
          Allocates a new direct ByteBuffer with the specified number of elements.
static FloatBuffer directFloatBuffer(float[] a)
          Allocates a new direct FloatBuffer with the specified number of elements.
static FloatBuffer directFloatBuffer(int numElements)
          Allocates a new direct FloatBuffer with the specified number of elements.
static IntBuffer directIntBuffer(int numElements)
          Allocates a new direct IntBuffer with the specified number of elements.
static IntBuffer directIntBuffer(int[] a)
          Allocates a new direct IntBuffer with the specified number of elements.
static ShortBuffer directShortBuffer(int numElements)
          Allocates a new direct ShortBuffer with the specified number of elements.
static FloatBuffer floatBuffer(float[] a)
          Converts a float array into a direct FloatBuffer.
static IntBuffer intBuffer(int[] a)
          Converts an int array into a direct IntBuffer.
static ShortBuffer shortBuffer(short[] a)
          Converts an short array into a direct ShortBuffer.
static ByteBuffer stringToNullTerminatedByteBuffer(String s)
          Converts a String into a direct ByteBuffer, after adding a null character at the end of the String
static String toString(ByteBuffer buf)
          Converts the bytes upto the current Buffer position from ByteBuffer buf into a String.
static String toString(ByteBuffer buf, int len)
          Converts the first len bytes from ByteBuffer buf into a String.
 
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_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

BufferUtil

private BufferUtil()
Method Detail

directFloatBuffer

public static FloatBuffer directFloatBuffer(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.


directFloatBuffer

public static FloatBuffer directFloatBuffer(float[] a)
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.


directIntBuffer

public static IntBuffer directIntBuffer(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.


directIntBuffer

public static IntBuffer directIntBuffer(int[] a)
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.


directShortBuffer

public static ShortBuffer directShortBuffer(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.


directByteBuffer

public static ByteBuffer directByteBuffer(int numElements)
Allocates a new direct ByteBuffer with the specified number of elements.


intBuffer

public static IntBuffer intBuffer(int[] a)
Converts an int array into a direct IntBuffer.


floatBuffer

public static FloatBuffer floatBuffer(float[] a)
Converts a float array into a direct FloatBuffer.


shortBuffer

public static ShortBuffer shortBuffer(short[] a)
Converts an short array into a direct ShortBuffer.


byteBuffer

public static ByteBuffer byteBuffer(byte[] a)
Converts an byte array into a direct ByteBuffer.


byteBuffer

public static ByteBuffer byteBuffer(String s)
Converts a String into a direct ByteBuffer.


stringToNullTerminatedByteBuffer

public static ByteBuffer stringToNullTerminatedByteBuffer(String s)
Converts a String into a direct ByteBuffer, after adding a null character at the end of the String


toString

public static String toString(ByteBuffer buf,
                              int len)
Converts the first len bytes from ByteBuffer buf into a String.


toString

public static String toString(ByteBuffer buf)
Converts the bytes upto the current Buffer position from ByteBuffer buf into a String.