NASA World Wind

gov.nasa.worldwind.util
Class BufferWrapper

java.lang.Object
  extended by gov.nasa.worldwind.util.BufferWrapper
Direct Known Subclasses:
BufferWrapper.AbstractBufferWrapper

public abstract class BufferWrapper
extends java.lang.Object

BufferWrapper provides an interface for reading and writing primitive data to and from data buffers, without having to know the underlying data type. BufferWrapper may be backed by a primitive data buffer of any type.


Nested Class Summary
static class BufferWrapper.AbstractBufferWrapper
           
static class BufferWrapper.ByteBufferWrapper
           
static class BufferWrapper.DoubleBufferWrapper
           
static class BufferWrapper.FloatBufferWrapper
           
static class BufferWrapper.IntBufferWrapper
           
static class BufferWrapper.ShortBufferWrapper
           
 
Constructor Summary
BufferWrapper()
           
 
Method Summary
abstract  java.nio.Buffer getBackingBuffer()
          Returns the buffer's backing data sture.
abstract  byte getByte(int index)
          Returns the value at the specified index, cast to a byte.
abstract  void getByte(int index, byte[] array, int offset, int length)
          Returns the sequence of values starting at the specified index and with the specified length, cast to bytes.
abstract  double getDouble(int index)
          Returns the value at the specified index, cast to a double.
abstract  void getDouble(int index, double[] array, int offset, int length)
          Returns the sequence of values starting at the specified index and with the specified length, cast to doubles.
abstract  float getFloat(int index)
          Returns the value at the specified index, cast to a float.
abstract  void getFloat(int index, float[] array, int offset, int length)
          Returns the sequence of values starting at the specified index and with the specified length, cast to floats.
abstract  int getGLDataType()
          Returns the OpenGL data type corresponding to the buffer's underlying data type (e.g.
abstract  int getInt(int index)
          Returns the value at the specified index, cast to an int.
abstract  void getInt(int index, int[] array, int offset, int length)
          Returns the sequence of values starting at the specified index and with the specified length, cast to ints.
abstract  short getShort(int index)
          Returns the value at the specified index, cast to a short.
abstract  void getShort(int index, short[] array, int offset, int length)
          Returns the sequence of values starting at the specified index and with the specified length, cast to shorts.
abstract  long getSizeInBytes()
          Returns the size of this buffer, in bytes.
abstract  BufferWrapper getSubBuffer(int index, int length)
          Returns a new BufferWrapper which is a subsequence of this buffer.
abstract  int length()
          Returns the length of the buffer, in units of the underlying data type (e.g. bytes, shorts, ints, floats, doubles).
abstract  void putByte(int index, byte value)
          Sets the value at the specified index as a byte.
abstract  void putByte(int index, byte[] array, int offset, int length)
          Sets the sequence of values starting at the specified index and with the specified length, as bytes.
abstract  void putDouble(int index, double value)
          Sets the value at the specified index as a double.
abstract  void putDouble(int index, double[] array, int offset, int length)
          Sets the sequence of values starting at the specified index and with the specified length, as doubles.
abstract  void putFloat(int index, float value)
          Sets the value at the specified index as a float.
abstract  void putFloat(int index, float[] array, int offset, int length)
          Sets the sequence of values starting at the specified index and with the specified length, as floats.
abstract  void putInt(int index, int value)
          Sets the value at the specified index as an int.
abstract  void putInt(int index, int[] array, int offset, int length)
          Sets the sequence of values starting at the specified index and with the specified length, as ints.
abstract  void putShort(int index, short value)
          Sets the value at the specified index as a short.
abstract  void putShort(int index, short[] array, int offset, int length)
          Sets the sequence of values starting at the specified index and with the specified length, as ints.
abstract  void putSubBuffer(int index, BufferWrapper buffer)
          Sets a subsequence of this buffer with the contents of the specified buffer.
protected static java.lang.String validate(AVList params)
           
protected static boolean validateByteOrder(java.lang.Object o)
           
protected static boolean validateDataType(java.lang.Object o)
           
static BufferWrapper wrap(java.nio.ByteBuffer byteBuffer, AVList parameters)
          Wraps the specified ByteBuffer with a BufferWrapper according to the specified parameters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BufferWrapper

public BufferWrapper()
Method Detail

getBackingBuffer

public abstract java.nio.Buffer getBackingBuffer()
Returns the buffer's backing data sture. For the standard BufferWrapper types (ByteBufferWrapper, ShortBufferWrapper, IntBufferWrapper, FloatBufferWrapper, and DoubleBufferWrapper), this returns the backing Buffer.

Returns:
the backing data store.

getByte

public abstract byte getByte(int index)
Returns the value at the specified index, cast to a byte.

Parameters:
index - the index of the value to be returned.
Returns:
the byte at the specified index.

getByte

public abstract void getByte(int index,
                             byte[] array,
                             int offset,
                             int length)
Returns the sequence of values starting at the specified index and with the specified length, cast to bytes.

Parameters:
index - the buffer starting index.
array - the array.
offset - the array starting index.
length - the number of values to get.

getDouble

public abstract double getDouble(int index)
Returns the value at the specified index, cast to a double.

Parameters:
index - the index of the value to be returned.
Returns:
the double at the specified index.

getDouble

public abstract void getDouble(int index,
                               double[] array,
                               int offset,
                               int length)
Returns the sequence of values starting at the specified index and with the specified length, cast to doubles.

Parameters:
index - the buffer starting index.
array - the array.
offset - the array starting index.
length - the number of values to get.

getFloat

public abstract float getFloat(int index)
Returns the value at the specified index, cast to a float.

Parameters:
index - the index of the value to be returned.
Returns:
the float at the specified index.

getFloat

public abstract void getFloat(int index,
                              float[] array,
                              int offset,
                              int length)
Returns the sequence of values starting at the specified index and with the specified length, cast to floats.

Parameters:
index - the buffer starting index.
array - the array.
offset - the array starting index.
length - the number of values to get.

getGLDataType

public abstract int getGLDataType()
Returns the OpenGL data type corresponding to the buffer's underlying data type (e.g. GL_BYTE, GL_SHORT, GL_INT, GL_FLOAT, GL_DOUBLE).

Returns:
the buffer's OpenGL data type.

getInt

public abstract int getInt(int index)
Returns the value at the specified index, cast to an int.

Parameters:
index - the index of the value to be returned.
Returns:
the int at the specified index.

getInt

public abstract void getInt(int index,
                            int[] array,
                            int offset,
                            int length)
Returns the sequence of values starting at the specified index and with the specified length, cast to ints.

Parameters:
index - the buffer starting index.
array - the array.
offset - the array starting index.
length - the number of values to get.

getShort

public abstract short getShort(int index)
Returns the value at the specified index, cast to a short.

Parameters:
index - the index of the value to be returned.
Returns:
the short at the specified index.

getShort

public abstract void getShort(int index,
                              short[] array,
                              int offset,
                              int length)
Returns the sequence of values starting at the specified index and with the specified length, cast to shorts.

Parameters:
index - the buffer starting index.
array - the array.
offset - the array starting index.
length - the number of values to get.

getSizeInBytes

public abstract long getSizeInBytes()
Returns the size of this buffer, in bytes.

Returns:
the buffer's size in bytes.

getSubBuffer

public abstract BufferWrapper getSubBuffer(int index,
                                           int length)
Returns a new BufferWrapper which is a subsequence of this buffer. The new buffer starts with the value at the specified index, and has the specified length. The two buffers share the same backing store, so changes to this buffer are reflected in the new buffer, and visa versa.

Parameters:
index - the new buffer's starting index.
length - the new buffer's length.
Returns:
a subsequence of this buffer.

length

public abstract int length()
Returns the length of the buffer, in units of the underlying data type (e.g. bytes, shorts, ints, floats, doubles).

Returns:
the buffer's length.

putByte

public abstract void putByte(int index,
                             byte value)
Sets the value at the specified index as a byte. The byte is cast to the underlying data type.

Parameters:
index - the index of the value to be returned.
value - the byte value to be set.

putByte

public abstract void putByte(int index,
                             byte[] array,
                             int offset,
                             int length)
Sets the sequence of values starting at the specified index and with the specified length, as bytes. The bytes are cast to the underlying data type.

Parameters:
index - the buffer starting index.
array - the array.
offset - the array starting index.
length - the number of values to put.

putDouble

public abstract void putDouble(int index,
                               double value)
Sets the value at the specified index as a double. The double is cast to the underlying data type.

Parameters:
index - the index of the value to be returned.
value - the double value to be set.

putDouble

public abstract void putDouble(int index,
                               double[] array,
                               int offset,
                               int length)
Sets the sequence of values starting at the specified index and with the specified length, as doubles. The doubles are cast to the underlying data type.

Parameters:
index - the buffer starting index.
array - the array.
offset - the array starting index.
length - the number of values to put.

putFloat

public abstract void putFloat(int index,
                              float value)
Sets the value at the specified index as a float. The float is cast to the underlying data type.

Parameters:
index - the index of the value to be returned.
value - the float value to be set.

putFloat

public abstract void putFloat(int index,
                              float[] array,
                              int offset,
                              int length)
Sets the sequence of values starting at the specified index and with the specified length, as floats. The floats are cast to the underlying data type.

Parameters:
index - the buffer starting index.
array - the array.
offset - the array starting index.
length - the number of values to put.

putInt

public abstract void putInt(int index,
                            int value)
Sets the value at the specified index as an int. The int is cast to the underlying data type.

Parameters:
index - the index of the value to be returned.
value - the int value to be set.

putInt

public abstract void putInt(int index,
                            int[] array,
                            int offset,
                            int length)
Sets the sequence of values starting at the specified index and with the specified length, as ints. The ints are cast to the underlying data type.

Parameters:
index - the buffer starting index.
array - the array.
offset - the array starting index.
length - the number of values to put.

putShort

public abstract void putShort(int index,
                              short value)
Sets the value at the specified index as a short. The short is cast to the underlying data type.

Parameters:
index - the index of the value to be returned.
value - the short value to be set.

putShort

public abstract void putShort(int index,
                              short[] array,
                              int offset,
                              int length)
Sets the sequence of values starting at the specified index and with the specified length, as ints. The ints are cast to the underlying data type.

Parameters:
index - the buffer starting index.
array - the array.
offset - the array starting index.
length - the number of values to put.

putSubBuffer

public abstract void putSubBuffer(int index,
                                  BufferWrapper buffer)
Sets a subsequence of this buffer with the contents of the specified buffer. The subsequence to set starts with the value at the specified index, and has length equal to the specified buffer's length.

Parameters:
index - the starting index to set.
buffer - the buffer.

validate

protected static java.lang.String validate(AVList params)

validateByteOrder

protected static boolean validateByteOrder(java.lang.Object o)

validateDataType

protected static boolean validateDataType(java.lang.Object o)

wrap

public static BufferWrapper wrap(java.nio.ByteBuffer byteBuffer,
                                 AVList parameters)
Wraps the specified ByteBuffer with a BufferWrapper according to the specified parameters. The byteBuffer is interpreted according to values found in the parameters. AVKey.BYTE_ORDER specifies the byteBuffer's byte ordering,. and AVKey.DATA_TYPE specifies type of data store in the byteBuffer: shorts, ints, or floats.

Parameters:
byteBuffer - the buffer to wrap.
parameters - the parameters which describe how to interpret the buffer.
Returns:
a new BufferWrapper backed by the specified byteBuffer.
Throws:
java.lang.IllegalArgumentException - if either the byteBuffer or parameters are null, or if the parameters do not completely describe how to interpret the byteBuffer.

NASA World Wind