net.clackrouter.protocol
Class VNSProtocolCharCoder

java.lang.Object
  extended by net.clackrouter.protocol.VNSProtocolCharCoder

public class VNSProtocolCharCoder
extends java.lang.Object

Transforms arbitrary strings into a buffer of bytes and vice versa using US ASCII encoding and decoding.


Field Summary
static java.nio.charset.Charset charset
          The US ASCII character set of the coder
static java.nio.charset.CharsetDecoder decoder
          Decoder of the US ASCII byte buffers
static java.nio.charset.CharsetEncoder encoder
          Encoder of the US ASCII strings
 
Constructor Summary
VNSProtocolCharCoder()
           
 
Method Summary
static java.lang.String decode(java.nio.ByteBuffer byteBuffer)
          Decodes the supplied byte buffer into a string using US ASCII decoding.
static java.lang.String decode(java.nio.ByteBuffer byteBuffer, boolean trim)
          Decodes the supplied byte buffer into a string using US ASCII decoding.
static java.lang.String decode(java.nio.ByteBuffer byteBuffer, int length)
          Decodes the supplied byte buffer into a string using US ASCII decoding.
static java.nio.ByteBuffer encode(java.lang.String message)
          Encodes the supplied message into a byte buffer using US ASCII encoding.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

charset

public static java.nio.charset.Charset charset
The US ASCII character set of the coder


encoder

public static java.nio.charset.CharsetEncoder encoder
Encoder of the US ASCII strings


decoder

public static java.nio.charset.CharsetDecoder decoder
Decoder of the US ASCII byte buffers

Constructor Detail

VNSProtocolCharCoder

public VNSProtocolCharCoder()
Method Detail

encode

public static java.nio.ByteBuffer encode(java.lang.String message)
                                  throws java.nio.charset.CharacterCodingException
Encodes the supplied message into a byte buffer using US ASCII encoding.

Parameters:
message - Message to be encoded
Returns:
Byte buffer containing the encoded message
Throws:
java.nio.charset.CharacterCodingException

decode

public static java.lang.String decode(java.nio.ByteBuffer byteBuffer)
                               throws java.nio.charset.CharacterCodingException
Decodes the supplied byte buffer into a string using US ASCII decoding.

Parameters:
byteBuffer - Byte buffer containing the encoded messasge
Returns:
Decoded message
Throws:
java.nio.charset.CharacterCodingException

decode

public static java.lang.String decode(java.nio.ByteBuffer byteBuffer,
                                      int length)
                               throws java.nio.charset.CharacterCodingException
Decodes the supplied byte buffer into a string using US ASCII decoding. The returned message is less than or equal to the specified length.

Parameters:
byteBuffer - Byte buffer containing the encoded messasge
length - Length of the returned message
Returns:
Decoded message
Throws:
java.nio.charset.CharacterCodingException

decode

public static java.lang.String decode(java.nio.ByteBuffer byteBuffer,
                                      boolean trim)
                               throws java.nio.charset.CharacterCodingException
Decodes the supplied byte buffer into a string using US ASCII decoding. Remove all the trailing spaces, starting from the first occurence of a space in the string.

Parameters:
byteBuffer - Byte buffer containing the encoded messasge
trim - If true, the message will be trimmed from the right
Returns:
Decoded message
Throws:
java.nio.charset.CharacterCodingException