org.jdesktop.wonderland.common.messages
Class MessagePacker

java.lang.Object
  extended by org.jdesktop.wonderland.common.messages.MessagePacker

public class MessagePacker
extends java.lang.Object

Utility class to pack and unpack messages to/from ByteBuffers.

Author:
paulby

Nested Class Summary
static class MessagePacker.PackerException
          Thrown when there is a problem packing or unpacking a Message
static class MessagePacker.ReceivedMessage
          A description of a received message.
 
Constructor Summary
MessagePacker()
           
 
Method Summary
protected static java.io.InputStream getInputStream(java.nio.ByteBuffer data)
          Convert a ByteBuffer into an input stream
static short getPackClassId(java.lang.Object obj)
          Return the id used to identify the class obj in the packed messages
static java.nio.ByteBuffer pack(Message message, short clientID)
          Pack the given message into a ByteBuffer ready for transmission over the network
static void setMessageMonitor(MessageMonitor monitor)
          Set the message monitor.
static MessagePacker.ReceivedMessage unpack(java.nio.ByteBuffer buf)
          Give a ByteBuffer unpack it's data and return the message it represents
static MessagePacker.ReceivedMessage unpack(java.nio.ByteBuffer buf, java.lang.ClassLoader classLoader)
          Give a ByteBuffer unpack it's data and return the message it represents.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MessagePacker

public MessagePacker()
Method Detail

getPackClassId

public static short getPackClassId(java.lang.Object obj)
Return the id used to identify the class obj in the packed messages

Parameters:
aThis -
Returns:

pack

public static java.nio.ByteBuffer pack(Message message,
                                       short clientID)
                                throws MessagePacker.PackerException
Pack the given message into a ByteBuffer ready for transmission over the network

Parameters:
message -
Returns:
Throws:
MessagePacker.PackerException

unpack

public static MessagePacker.ReceivedMessage unpack(java.nio.ByteBuffer buf)
                                            throws MessagePacker.PackerException
Give a ByteBuffer unpack it's data and return the message it represents

Parameters:
buf -
Returns:
Throws:
MessagePacker.PackerException

unpack

public static MessagePacker.ReceivedMessage unpack(java.nio.ByteBuffer buf,
                                                   java.lang.ClassLoader classLoader)
                                            throws MessagePacker.PackerException
Give a ByteBuffer unpack it's data and return the message it represents. Use the provided classloader to resolve the message class.

Parameters:
buf - the buffer to unpack
classLoader - the classloader to resolve the class with
Returns:
the unpacked message
Throws:
MessagePacker.PackerException

getInputStream

protected static java.io.InputStream getInputStream(java.nio.ByteBuffer data)
Convert a ByteBuffer into an input stream

Parameters:
data - the byte array
Returns:
an input stream for reading from the ByteBuffer

setMessageMonitor

public static void setMessageMonitor(MessageMonitor monitor)
Set the message monitor.

Parameters:
monitor -


Open Wonderland - http://openwonderland.org