com.mooapi.common.message
Class MessageCodec

java.lang.Object
  extended by com.mooapi.common.message.MessageCodec

public class MessageCodec
extends java.lang.Object

Author:
Steve Taylor

Constructor Summary
MessageCodec()
          Create a message codec using the default character set for string decoding/encoding.
MessageCodec(java.nio.charset.Charset charset)
          Create a message codec using the specified character set for string decoding/encoding.
 
Method Summary
 StringMessage createStringMessage(java.lang.String string)
          Create a string message from the specified string, using this codec's current character set to encode it.
 AbstractMessage decode(org.apache.mina.common.ByteBuffer message)
          Decode a byte-stream message.
 org.apache.mina.common.ByteBuffer encode(AbstractMessage message)
          Encode a message to a byte stream.
 void setCharset(java.nio.charset.Charset charset)
          Set the character set used to decode string messages.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MessageCodec

public MessageCodec(java.nio.charset.Charset charset)
Create a message codec using the specified character set for string decoding/encoding.

Parameters:
charset - A character set.

MessageCodec

public MessageCodec()

Create a message codec using the default character set for string decoding/encoding.

Equivalent to MessageCodec(Charset.defaultCharset().

Method Detail

setCharset

public void setCharset(java.nio.charset.Charset charset)
Set the character set used to decode string messages.

Parameters:
charset - The string message character set.

decode

public AbstractMessage decode(org.apache.mina.common.ByteBuffer message)
Decode a byte-stream message. The caller should not modify the contents of the message array after calling this message as the decoded message may be backed by the array.

Parameters:
message - An encoded message.
Returns:
The decoded message.

encode

public org.apache.mina.common.ByteBuffer encode(AbstractMessage message)
Encode a message to a byte stream. The caller should not modify the contents of the returned buffer as it may back the original message.

Parameters:
message - The message to encode.
Returns:
The encoded message.

createStringMessage

public StringMessage createStringMessage(java.lang.String string)
Create a string message from the specified string, using this codec's current character set to encode it.

Parameters:
string - A string.
Returns:
A string message.


Copyright © 2009. All Rights Reserved.