utilities
Class LengthPrefixMessage

java.lang.Object
  |
  +--utilities.Message
        |
        +--utilities.LengthPrefixMessage
All Implemented Interfaces:
java.lang.Cloneable

public class LengthPrefixMessage
extends Message

A message encoding where the content length is prepended to the message in a fixed width field (e.g. a valid message would be "0005hello"). Currently, this field with is fixed in the PREFIXLEN constant.


Constructor Summary
LengthPrefixMessage(java.lang.Object c, java.lang.String da)
          A "tell" message
LengthPrefixMessage(java.lang.String s)
          Send in your encoded message to decode it
LengthPrefixMessage(java.lang.String p, java.lang.Object c, java.lang.String da)
          Normal constructor
 
Method Summary
static java.lang.String receive(java.io.BufferedReader b)
          Reads it in, first looking for the length prefix, then using that to read the content.
 void setContent(java.lang.Object c)
          Sets the message's content string
 
Methods inherited from class utilities.Message
clone, contentData, contentData, contentWord, contentWord, getConnection, getContent, getData, getDestAddr, getDestPort, getReceiveTime, getSendTime, getSourceAddr, getSourcePort, receive, receive, send, send, setConnection, setData, setDestAddr, setDestPort, setReceiveTime, setSendTime, setSourceAddr, setSourcePort, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LengthPrefixMessage

public LengthPrefixMessage(java.lang.String s)
Send in your encoded message to decode it
Parameters:
s - The length-prefixed message to decode

LengthPrefixMessage

public LengthPrefixMessage(java.lang.Object c,
                           java.lang.String da)
A "tell" message
Parameters:
c - The content to send
da - The destination address

LengthPrefixMessage

public LengthPrefixMessage(java.lang.String p,
                           java.lang.Object c,
                           java.lang.String da)
Normal constructor
Parameters:
p - The message performative (e.g. "ask", "tell", etc.)
c - The content to send
da - The destination address
Method Detail

receive

public static java.lang.String receive(java.io.BufferedReader b)
Reads it in, first looking for the length prefix, then using that to read the content.
Parameters:
b - The reader used to get the message
Returns:
The message data, or null if error occurs

setContent

public void setContent(java.lang.Object c)
Sets the message's content string
Overrides:
setContent in class Message
Parameters:
c - The content