multiverse.server.network
Class MVByteBuffer

java.lang.Object
  extended by multiverse.server.network.MVByteBuffer
All Implemented Interfaces:
Cloneable, Comparable<MVByteBuffer>

public class MVByteBuffer
extends Object
implements Cloneable, Comparable<MVByteBuffer>


Field Summary
private static Map<Class,Byte> classToValueTypeMap
           
private  ByteBuffer mBB
           
private static byte valueTypeBoolean
           
private static byte valueTypeBooleanFalse
           
private static byte valueTypeBooleanTrue
           
private static byte valueTypeByte
           
private static byte valueTypeByteArray
           
private static byte valueTypeColor
           
private static byte valueTypeDouble
           
private static byte valueTypeFloat
           
private static byte valueTypeHashMap
           
private static byte valueTypeHashSet
           
private static byte valueTypeInteger
           
private static byte valueTypeLinkedList
           
private static byte valueTypeLong
           
private static byte valueTypeMVVector
           
private static byte valueTypeNull
           
private static byte valueTypePoint
           
private static byte valueTypeQuaternion
           
private static byte valueTypeShort
           
private static byte valueTypeString
           
private static byte valueTypeTreeMap
           
 
Constructor Summary
MVByteBuffer(byte[] data)
          creates a new byte buffer that is the length of the byte array passed in and places the bytes into the new buffer.
MVByteBuffer(ByteBuffer data)
           
MVByteBuffer(int size)
           
 
Method Summary
 byte[] array()
          returns the backing array - not useful to send across network the backing array encoding format may not be the same as what you entered and therefore you should use getBytes instead.
 int capacity()
           
 MVByteBuffer clear()
           
 Object clone()
          returns a copy of the byte buffer
 MVByteBuffer cloneAtOffset(int offset, int length)
          Returns the MVByteBuffer gotten by skipping the first offset bytes in the original buffer, and copying out by length
 int compareTo(MVByteBuffer buffer)
           
 byte[] copyBytes()
          basically helper function to getBytes that rewinds first and returns a copy of the bytes.
 byte[] copyBytesFromZeroToLimit()
          this version of copyBytes gets the same bytes as the version above, with the same goofy business of ignoring the starting position, but this version also doesn't change position.
 MVByteBuffer flip()
           
 boolean getBoolean()
           
 byte getByte()
           
 byte[] getByteArray()
           
 MVByteBuffer getByteBuffer()
           
 MVByteBuffer getBytes(byte[] dst, int offset, int length)
           
 Color getColor()
           
 double getDouble()
           
 Serializable getEncodedObject()
           
 float getFloat()
           
 int getInt()
           
 long getLong()
           
 MVVector getMVVector()
           
 ByteBuffer getNioBuf()
           
 Point getPoint()
           
 Map<String,Serializable> getPropertyMap()
           
 Quaternion getQuaternion()
           
 short getShort()
           
 String getString()
           
 Map<String,Serializable> getTreeMap()
           
 boolean hasRemaining()
           
private static void initializeClassToValueTypeMap()
           
 int limit()
           
 MVByteBuffer limit(int newLimit)
           
private  void logPropertyMap(String prefix, Map<String,Serializable> propertyMap, Set<String> filteredProps)
           
static void main(String[] args)
           
 int position()
           
 MVByteBuffer position(int newPos)
           
 MVByteBuffer putBoolean(boolean b)
           
 MVByteBuffer putByte(byte b)
           
 MVByteBuffer putByteArray(byte[] byteArray)
           
 MVByteBuffer putByteBuffer(MVByteBuffer other)
           
 MVByteBuffer putBytes(byte[] src, int offset, int length)
           
 MVByteBuffer putColor(Color c)
           
 MVByteBuffer putDouble(double d)
           
 void putEncodedObject(Serializable val)
           
 void putFilteredPropertyMap(Map<String,Serializable> propertyMap, Set<String> filteredProps)
           
 MVByteBuffer putFloat(float f)
           
 MVByteBuffer putInt(int i)
           
 MVByteBuffer putLong(long l)
           
 MVByteBuffer putMsgTypeString(MessageType msgType)
           
 MVByteBuffer putMVVector(MVVector v)
           
 MVByteBuffer putPoint(Point p)
           
 void putPropertyMap(Map<String,Serializable> propertyMap)
           
 MVByteBuffer putQuaternion(Quaternion q)
           
 MVByteBuffer putShort(short s)
           
 MVByteBuffer putString(String s)
           
private  void reallocate()
           
private  void reallocate(int minSize)
           
 int remaining()
           
 MVByteBuffer rewind()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

valueTypeNull

private static final byte valueTypeNull
See Also:
Constant Field Values

valueTypeString

private static final byte valueTypeString
See Also:
Constant Field Values

valueTypeLong

private static final byte valueTypeLong
See Also:
Constant Field Values

valueTypeInteger

private static final byte valueTypeInteger
See Also:
Constant Field Values

valueTypeBoolean

private static final byte valueTypeBoolean
See Also:
Constant Field Values

valueTypeBooleanFalse

private static final byte valueTypeBooleanFalse
See Also:
Constant Field Values

valueTypeBooleanTrue

private static final byte valueTypeBooleanTrue
See Also:
Constant Field Values

valueTypeFloat

private static final byte valueTypeFloat
See Also:
Constant Field Values

valueTypeDouble

private static final byte valueTypeDouble
See Also:
Constant Field Values

valueTypePoint

private static final byte valueTypePoint
See Also:
Constant Field Values

valueTypeMVVector

private static final byte valueTypeMVVector
See Also:
Constant Field Values

valueTypeQuaternion

private static final byte valueTypeQuaternion
See Also:
Constant Field Values

valueTypeColor

private static final byte valueTypeColor
See Also:
Constant Field Values

valueTypeByte

private static final byte valueTypeByte
See Also:
Constant Field Values

valueTypeShort

private static final byte valueTypeShort
See Also:
Constant Field Values

valueTypeLinkedList

private static final byte valueTypeLinkedList
See Also:
Constant Field Values

valueTypeHashSet

private static final byte valueTypeHashSet
See Also:
Constant Field Values

valueTypeHashMap

private static final byte valueTypeHashMap
See Also:
Constant Field Values

valueTypeByteArray

private static final byte valueTypeByteArray
See Also:
Constant Field Values

valueTypeTreeMap

private static final byte valueTypeTreeMap
See Also:
Constant Field Values

classToValueTypeMap

private static Map<Class,Byte> classToValueTypeMap

mBB

private ByteBuffer mBB
Constructor Detail

MVByteBuffer

public MVByteBuffer(int size)

MVByteBuffer

public MVByteBuffer(byte[] data)
creates a new byte buffer that is the length of the byte array passed in and places the bytes into the new buffer. flips the buffer for reading


MVByteBuffer

public MVByteBuffer(ByteBuffer data)
Method Detail

clone

public Object clone()
returns a copy of the byte buffer

Overrides:
clone in class Object

cloneAtOffset

public MVByteBuffer cloneAtOffset(int offset,
                                  int length)
Returns the MVByteBuffer gotten by skipping the first offset bytes in the original buffer, and copying out by length


array

public byte[] array()
returns the backing array - not useful to send across network the backing array encoding format may not be the same as what you entered and therefore you should use getBytes instead.


capacity

public int capacity()

clear

public MVByteBuffer clear()

flip

public MVByteBuffer flip()

hasRemaining

public boolean hasRemaining()

limit

public int limit()

limit

public MVByteBuffer limit(int newLimit)

position

public int position()

position

public MVByteBuffer position(int newPos)

remaining

public int remaining()

rewind

public MVByteBuffer rewind()

getByte

public byte getByte()

getBytes

public MVByteBuffer getBytes(byte[] dst,
                             int offset,
                             int length)

copyBytes

public byte[] copyBytes()
basically helper function to getBytes that rewinds first and returns a copy of the bytes. uses limit (set by flip() ) to figure out how much to copy and leaves position at the end.


copyBytesFromZeroToLimit

public byte[] copyBytesFromZeroToLimit()
this version of copyBytes gets the same bytes as the version above, with the same goofy business of ignoring the starting position, but this version also doesn't change position.


getBoolean

public boolean getBoolean()

getDouble

public double getDouble()

getFloat

public float getFloat()

getShort

public short getShort()

getInt

public int getInt()

getLong

public long getLong()

getString

public String getString()

getPoint

public Point getPoint()

getQuaternion

public Quaternion getQuaternion()

getMVVector

public MVVector getMVVector()

getColor

public Color getColor()

getByteBuffer

public MVByteBuffer getByteBuffer()

getByteArray

public byte[] getByteArray()

putByte

public MVByteBuffer putByte(byte b)

putBytes

public MVByteBuffer putBytes(byte[] src,
                             int offset,
                             int length)

putBoolean

public MVByteBuffer putBoolean(boolean b)

putDouble

public MVByteBuffer putDouble(double d)

putFloat

public MVByteBuffer putFloat(float f)

putShort

public MVByteBuffer putShort(short s)

putInt

public MVByteBuffer putInt(int i)

putLong

public MVByteBuffer putLong(long l)

putString

public MVByteBuffer putString(String s)

putMsgTypeString

public MVByteBuffer putMsgTypeString(MessageType msgType)

putPoint

public MVByteBuffer putPoint(Point p)

putQuaternion

public MVByteBuffer putQuaternion(Quaternion q)

putMVVector

public MVByteBuffer putMVVector(MVVector v)

putColor

public MVByteBuffer putColor(Color c)

putByteBuffer

public MVByteBuffer putByteBuffer(MVByteBuffer other)

putByteArray

public MVByteBuffer putByteArray(byte[] byteArray)

getNioBuf

public ByteBuffer getNioBuf()

reallocate

private void reallocate()

reallocate

private void reallocate(int minSize)

initializeClassToValueTypeMap

private static void initializeClassToValueTypeMap()

putEncodedObject

public void putEncodedObject(Serializable val)

getEncodedObject

public Serializable getEncodedObject()

putPropertyMap

public void putPropertyMap(Map<String,Serializable> propertyMap)

putFilteredPropertyMap

public void putFilteredPropertyMap(Map<String,Serializable> propertyMap,
                                   Set<String> filteredProps)

logPropertyMap

private void logPropertyMap(String prefix,
                            Map<String,Serializable> propertyMap,
                            Set<String> filteredProps)

getPropertyMap

public Map<String,Serializable> getPropertyMap()

getTreeMap

public Map<String,Serializable> getTreeMap()

compareTo

public int compareTo(MVByteBuffer buffer)
Specified by:
compareTo in interface Comparable<MVByteBuffer>

main

public static void main(String[] args)