org.jouvieje.fmodex.utils
Class BufferUtils

java.lang.Object
  extended byorg.jouvieje.fmodex.utils.BufferUtils
All Implemented Interfaces:
SizeOfPrimitive

public class BufferUtils
extends java.lang.Object
implements SizeOfPrimitive

Utility routines for dealing with direct buffers.

ABOUT THIS CLASS

This class is based on BufferUtils of JOGL from the package net.java.games.jogl.util
I've added in it few others routines.


Here is the copyright related to this file :

Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.

 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions are
 met:

 - Redistribution of source code must retain the above copyright
   notice, this list of conditions and the following disclaimer.

 - Redistribution in binary form must reproduce the above copyright
   notice, this list of conditions and the following disclaimer in the
   documentation and/or other materials provided with the distribution.

 Neither the name of Sun Microsystems, Inc. or the names of
 contributors may be used to endorse or promote products derived from
 this software without specific prior written permission.

 This software is provided "AS IS," without a warranty of any kind. ALL
 EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
 INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
 PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
 MIDROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
 ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
 DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
 ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
 DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
 DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
 ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
 SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

 You acknowledge that this software is not designed or intended for use
 in the design, construction, operation or maintenance of any nuclear
 facility.

 Sun gratefully acknowledges that this software was originally authored
 and developed by Kenneth Bradley Russell and Christopher John Kline.


Field Summary
 
Fields inherited from interface org.jouvieje.fmodex.utils.SizeOfPrimitive
SIZEOF_BYTE, SIZEOF_CHAR, SIZEOF_DOUBLE, SIZEOF_FLOAT, SIZEOF_INT, SIZEOF_LONG, SIZEOF_SHORT
 
Constructor Summary
BufferUtils()
           
 
Method Summary
static Pointer asPointer(java.nio.Buffer buffer)
          Create a view of the Buffer object as a Pointer object.
static java.nio.ByteBuffer copyByteBuffer(java.nio.ByteBuffer src)
          Make a copy of an existing buffer (src) to a new buffer (dest)
static java.nio.DoubleBuffer copyDoubleBuffer(java.nio.DoubleBuffer src)
          Make a copy of an existing buffer (src) to a new buffer (dest)
static java.nio.FloatBuffer copyFloatBuffer(java.nio.FloatBuffer src)
          Make a copy of an existing buffer (src) to a new buffer (dest)
static java.nio.IntBuffer copyIntBuffer(java.nio.IntBuffer src)
          Make a copy of an existing buffer (src) to a new buffer (dest)
static java.nio.LongBuffer copyLongBuffer(java.nio.LongBuffer src)
          Make a copy of an existing buffer (src) to a new buffer (dest)
static java.nio.ShortBuffer copyShortBuffer(java.nio.ShortBuffer src)
          Make a copy of an existing buffer (src) to a new buffer (dest)
static java.nio.ByteBuffer fromString(java.lang.String s)
          Create a ByteBuffer containing a null terminated string (UTF-8).
static java.nio.ByteBuffer fromStringUTF16(java.lang.String s)
          Create a ByteBuffer containing a null terminated string (UTF-16LE).
static int getCapacityInBytes(java.nio.Buffer buffer)
           
static int getPositionInBytes(java.nio.Buffer buffer)
           
static java.nio.ByteBuffer newByteBuffer(int nbElements)
          Allocate a new direct buffer
static java.nio.CharBuffer newCharBuffer(int nbElements)
          Allocate a new direct buffer
static java.nio.DoubleBuffer newDoubleBuffer(int nbElements)
          Allocate a new direct buffer
static java.nio.FloatBuffer newFloatBuffer(int nbElements)
          Allocate a new direct buffer
static java.nio.IntBuffer newIntBuffer(int nbElements)
          Allocate a new direct buffer
static java.nio.LongBuffer newLongBuffer(int nbElements)
          Allocate a new direct buffer
static java.nio.ShortBuffer newShortBuffer(int nbElements)
          Allocate a new direct buffer
static void putNullTerminal(java.nio.ByteBuffer buffer)
          Relative put operation.
static void putString(java.nio.ByteBuffer buffer, java.lang.String s)
          Relative put operation.
static void putString(java.nio.ByteBuffer buffer, java.lang.String s, java.lang.String charset)
           
static java.lang.String toString(java.nio.ByteBuffer buffer)
          Retrieve the String stored in the Buffer (Null terminated String).
static java.lang.String toString(java.nio.ByteBuffer buffer, int offset, int length)
          Retrieve the String stored in the Buffer.
static java.lang.String toString(java.nio.CharBuffer charBuffer)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BufferUtils

public BufferUtils()
Method Detail

newByteBuffer

public static java.nio.ByteBuffer newByteBuffer(int nbElements)
Allocate a new direct buffer

Parameters:
nbElements - size of the ByteBuffer in bytes.
Returns:
new direct buffer that holds nbElements bytes.

newCharBuffer

public static java.nio.CharBuffer newCharBuffer(int nbElements)
Allocate a new direct buffer

Parameters:
nbElements - size of the ByteBuffer in chars.
Returns:
new direct buffer that holds nbElements chars.

newShortBuffer

public static java.nio.ShortBuffer newShortBuffer(int nbElements)
Allocate a new direct buffer

Parameters:
nbElements - size of the ByteBuffer in shorts.
Returns:
new direct buffer that holds nbElements shorts.

newIntBuffer

public static java.nio.IntBuffer newIntBuffer(int nbElements)
Allocate a new direct buffer

Parameters:
nbElements - size of the ByteBuffer in ints.
Returns:
new direct buffer that holds nbElements bytes.

newLongBuffer

public static java.nio.LongBuffer newLongBuffer(int nbElements)
Allocate a new direct buffer

Parameters:
nbElements - size of the ByteBuffer in longs.
Returns:
new direct buffer that holds nbElements longs.

newFloatBuffer

public static java.nio.FloatBuffer newFloatBuffer(int nbElements)
Allocate a new direct buffer

Parameters:
nbElements - size of the ByteBuffer in floats.
Returns:
new direct buffer that holds nbElements floats.

newDoubleBuffer

public static java.nio.DoubleBuffer newDoubleBuffer(int nbElements)
Allocate a new direct buffer

Parameters:
nbElements - size of the ByteBuffer in doubles.
Returns:
new direct buffer that holds nbElements doubles.

copyByteBuffer

public static java.nio.ByteBuffer copyByteBuffer(java.nio.ByteBuffer src)
Make a copy of an existing buffer (src) to a new buffer (dest)

Parameters:
src - existing buffer to make a copy
Returns:
the new buffer copied

copyShortBuffer

public static java.nio.ShortBuffer copyShortBuffer(java.nio.ShortBuffer src)
Make a copy of an existing buffer (src) to a new buffer (dest)

Parameters:
src - existing buffer to make a copy
Returns:
the new buffer copied

copyIntBuffer

public static java.nio.IntBuffer copyIntBuffer(java.nio.IntBuffer src)
Make a copy of an existing buffer (src) to a new buffer (dest)

Parameters:
src - existing buffer to make a copy
Returns:
the new buffer copied

copyLongBuffer

public static java.nio.LongBuffer copyLongBuffer(java.nio.LongBuffer src)
Make a copy of an existing buffer (src) to a new buffer (dest)

Parameters:
src - existing buffer to make a copy
Returns:
the new buffer copied

copyFloatBuffer

public static java.nio.FloatBuffer copyFloatBuffer(java.nio.FloatBuffer src)
Make a copy of an existing buffer (src) to a new buffer (dest)

Parameters:
src - existing buffer to make a copy
Returns:
the new buffer copied

copyDoubleBuffer

public static java.nio.DoubleBuffer copyDoubleBuffer(java.nio.DoubleBuffer src)
Make a copy of an existing buffer (src) to a new buffer (dest)

Parameters:
src - existing buffer to make a copy
Returns:
the new buffer copied

getCapacityInBytes

public static int getCapacityInBytes(java.nio.Buffer buffer)
Parameters:
buffer - a buffer
Returns:
the capacity in byts of the buffer.
-1 if the buffer type is unknow

getPositionInBytes

public static int getPositionInBytes(java.nio.Buffer buffer)
Parameters:
buffer - a buffer
Returns:
the capacity in byts of the buffer.
-1 if the buffer type is unknow

toString

public static java.lang.String toString(java.nio.ByteBuffer buffer)
Retrieve the String stored in the Buffer (Null terminated String).

Parameters:
buffer - a buffer that holds a String.
Returns:
the String holded by the Buffer.
null if no String stored in the Buffer.
See Also:
toString(ByteBuffer, int, int)

toString

public static java.lang.String toString(java.nio.ByteBuffer buffer,
                                        int offset,
                                        int length)
Retrieve the String stored in the Buffer.

Parameters:
buffer - a buffer that holds a String.
offset - offset (in bytes) from the current position in the ByteBuffer.
length - length of the String to retrieve from the buffer.
Returns:
the string composed of the length first characters stored into the Buffer
See Also:
toString(ByteBuffer)

toString

public static java.lang.String toString(java.nio.CharBuffer charBuffer)

fromString

public static java.nio.ByteBuffer fromString(java.lang.String s)
Create a ByteBuffer containing a null terminated string (UTF-8).

Parameters:
s - a string
Returns:
byte buffer containing the string
See Also:
fromStringUTF16(String)

fromStringUTF16

public static java.nio.ByteBuffer fromStringUTF16(java.lang.String s)
Create a ByteBuffer containing a null terminated string (UTF-16LE).

Parameters:
s - a string
Returns:
byte buffer containing the string
See Also:
fromString(String)

putString

public static void putString(java.nio.ByteBuffer buffer,
                             java.lang.String s)
Relative put operation.
Write a String in a ByteBuffer object.

In some case, you also need to put a NULL terminal character at the end of the string. For this use putNullTerminalCharacter.

Parameters:
buffer - a destination buffer for the String.
s - a String to copy in the Buffer
See Also:
putNullTerminal(ByteBuffer)

putString

public static void putString(java.nio.ByteBuffer buffer,
                             java.lang.String s,
                             java.lang.String charset)
Parameters:
charset - string encoding
See Also:
putString(ByteBuffer, String), putNullTerminal(ByteBuffer)

putNullTerminal

public static void putNullTerminal(java.nio.ByteBuffer buffer)
Relative put operation.
Write a NULL terminal character in a ByteBuffer object.

Parameters:
buffer - a destination buffer for the String.

asPointer

public static Pointer asPointer(java.nio.Buffer buffer)
Create a view of the Buffer object as a Pointer object.

Parameters:
buffer - a direct ByteBuffer
Returns:
the Pointer view.


NativeFmodEx Project - © Copyright 2005-2010 - Jérôme Jouvie (Jouvieje)
NativeFmodEx is an Open Source Project under GNU LGPL License
My sites : http://jerome.jouvie.free.fr/

(Documentation Copyright © Firelight Technologies - FMOD Ex - http://www.fmod.org)