NASA World Wind

gov.nasa.worldwind.util
Class BufferWrapper

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

public abstract class BufferWrapper
extends 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<T extends Buffer>
           
static class BufferWrapper.ByteBufferWrapper
           
static class BufferWrapper.DoubleBufferWrapper
           
protected static class BufferWrapper.EmptyBufferWrapper
           
static class BufferWrapper.FloatBufferWrapper
           
static class BufferWrapper.IntBufferWrapper
           
static class BufferWrapper.ShortBufferWrapper
           
 
Field Summary
protected static BufferWrapper EMPTY_BUFFER_WRAPPER
           
 
Constructor Summary
BufferWrapper()
           
 
Method Summary
abstract  BufferWrapper copyOf(int newSize)
          Returns a copy of this buffer with the specified new size.
static BufferWrapper emptyBufferWrapper()
          Returns the empty BufferWrapper.
abstract  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.
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.
abstract  void putSubBuffer(int index, BufferWrapper buffer, int offset, int length)
          Sets a subsequence of this buffer with the contents of the specified buffer.
static BufferWrapper wrap(ByteBuffer byteBuffer, AVList params)
          Wraps the specified ByteBuffer with a BufferWrapper according to the specified parameters.
static BufferWrapper wrap(ByteBuffer byteBuffer, Object dataType)
          Wraps the specified ByteBuffer with a BufferWrapper according to the specified primitive dataType.
static BufferWrapper wrap(ByteBuffer byteBuffer, Object dataType, Object byteOrder)
          Wraps the specified ByteBuffer with a BufferWrapper according to the specified primitive dataType and byteOrder.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_BUFFER_WRAPPER

protected static final BufferWrapper EMPTY_BUFFER_WRAPPER
Constructor Detail

BufferWrapper

public BufferWrapper()
Method Detail

copyOf

public abstract BufferWrapper copyOf(int newSize)
Returns a copy of this buffer with the specified new size. The new size must be greater than or equal to this buffer's size. If the new size is greater than this buffer's size, this returns a new buffer which is partially filled with the contents of this buffer. The returned buffer has the same backing buffer type, but its contents are independent from this VecBuffer.

Parameters:
newSize - the new buffer's size.
Returns:
the new buffer, with the specified size.

emptyBufferWrapper

public static BufferWrapper emptyBufferWrapper()
Returns the empty BufferWrapper. The returned BufferWrapper is immutable and has no backing Buffer.

Returns:
the empty BufferWrapper.

getBackingBuffer

public abstract 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 vice 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.

putSubBuffer

public abstract void putSubBuffer(int index,
                                  BufferWrapper buffer,
                                  int offset,
                                  int length)
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 length.

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

wrap

public static BufferWrapper wrap(ByteBuffer byteBuffer,
                                 AVList params)
Wraps the specified ByteBuffer with a BufferWrapper according to the specified parameters. The AVKey.DATA_TYPE parameter is required, and describes the primitive data type stored in the ByteBuffer: shorts, ints, floats, or doubles. The AVKey.BYTE_ORDER parameter is optional, and describes the ByteBuffer's byte ordering.

Parameters:
byteBuffer - the buffer to wrap.
params - the parameters which describe how to interpret the buffer.
Returns:
a new BufferWrapper backed by the specified byteBuffer.
Throws:
IllegalArgumentException - if either the byteBuffer or the parameters are null, or if AVKey.DATA_TYPE parameter is missing.

wrap

public static BufferWrapper wrap(ByteBuffer byteBuffer,
                                 Object dataType)
Wraps the specified ByteBuffer with a BufferWrapper according to the specified primitive dataType. The dataType describes the primitive data type stored in the ByteBuffer: shorts, ints, floats, or doubles. This assumes the ByteBuffer's current byte ordering.

Parameters:
byteBuffer - the buffer to wrap.
dataType - the primitive data type stored in the ByteBuffer.
Returns:
a new BufferWrapper backed by the specified byteBuffer.
Throws:
IllegalArgumentException - if either the byteBuffer or the data type are null.

wrap

public static BufferWrapper wrap(ByteBuffer byteBuffer,
                                 Object dataType,
                                 Object byteOrder)
Wraps the specified ByteBuffer with a BufferWrapper according to the specified primitive dataType and byteOrder. The dataType describes the primitive data type stored in the ByteBuffer: shorts, ints, floats, or doubles. The byteOrder describes the ByteBuffer's byte ordering. A null byteOrder indicates that the ByteBuffer's current byte ordering should be used.

Parameters:
byteBuffer - the buffer to wrap.
dataType - the primitive data type stored in the ByteBuffer.
byteOrder - the primitive byte ordering of the ByteBuffer, or null to use the ByteBuffer's current ordering.
Returns:
a new BufferWrapper backed by the specified byteBuffer.
Throws:
IllegalArgumentException - if either the byteBuffer or the data type are null.

NASA World Wind