com.mooapi.common.message
Class BinaryMessage

java.lang.Object
  extended by com.mooapi.common.message.AbstractMessage<T>
      extended by com.mooapi.common.message.AbstractTypedMessage<byte[]>
          extended by com.mooapi.common.message.BinaryMessage

public class BinaryMessage
extends AbstractTypedMessage<byte[]>

Binary message base type. For performance reasons, this message type is backed a ByteBuffer instead of its own byte array, taking advantage of Apache MINA's ByteBuffer pooling.

Author:
Steve Taylor

Constructor Summary
BinaryMessage(byte[] message)
          Wrap the specified byte array.
 
Method Summary
 RawMessage asRawMessage()
          Convert this message into a raw message.
static BinaryMessage decode(org.apache.mina.common.ByteBuffer message)
          Decode the binary message, including the leading type byte.
protected  org.apache.mina.common.ByteBuffer encodeBody()
          Encode the binary data, excluding the leading type byte.
 int getEncodedLength()
          Get the length, in bytes, of this message when encoded.
 MessageType getType()
          Get this message's type.
 
Methods inherited from class com.mooapi.common.message.AbstractTypedMessage
encode, equals, hashCode, toString
 
Methods inherited from class com.mooapi.common.message.AbstractMessage
getMessage
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BinaryMessage

public BinaryMessage(byte[] message)
Wrap the specified byte array.

Parameters:
message - The byte array.
Method Detail

getType

public MessageType getType()
Description copied from class: AbstractTypedMessage
Get this message's type.

Specified by:
getType in class AbstractTypedMessage<byte[]>
Returns:
The type.

decode

public static BinaryMessage decode(org.apache.mina.common.ByteBuffer message)
Decode the binary message, including the leading type byte. If an exception is thrown, the byte buffer's position is restored (using mark/reset) and the exception is propagated.

Parameters:
message - The bytes to decode.
Returns:
The decoded message.
Throws:
java.lang.IllegalArgumentException - if the leading type byte is not MessageType.BINARY.
java.nio.BufferUnderflowException - if message is empty.

getEncodedLength

public int getEncodedLength()
Description copied from class: AbstractMessage
Get the length, in bytes, of this message when encoded.

Specified by:
getEncodedLength in class AbstractMessage<byte[]>
Returns:

encodeBody

protected org.apache.mina.common.ByteBuffer encodeBody()
Encode the binary data, excluding the leading type byte. The ByteBuffer that backs this message is rewound and returned, so any changes made to the returned buffer will change this message.

Specified by:
encodeBody in class AbstractTypedMessage<byte[]>
Returns:
The encoded binary data.

asRawMessage

public RawMessage asRawMessage()
Convert this message into a raw message.

Specified by:
asRawMessage in class AbstractMessage<byte[]>
Returns:
A new raw message.


Copyright © 2009. All Rights Reserved.