Class Message

Class Message

java.lang.Object
   |
   +----Message

class Message
extends Object
A class designed to be used as a general network byte message wrapping class.

For a Message to be valid, it should be created using some MessageCreator method and then parsed using the MessageParser. It's not enough to create a Message with it's constructor and just feed it further. You should use the MessageCreator for any message you create. The simplicity is the same.
[IN WORK: Implementing Extensive Validity]

Written: Radu Sion
Version: 0.21
Source: Message.java
See Also:
MessageCreator, MessageParser

Constructor Index

 o Message(byte[])
Constructs a message based on a bytes array.
 o Message(int)
Constructs a null message based on a given length.
 o Message(Message)
Constructs a message based on another message, it is just like duplicating.
 o Message(String)
Constructs a message based on a string.

Method Index

 o byteAt(int)
Returns a byte at a given index in the Message.
 o byteAt(int, int)
Sets a byte at a given index in the Message, with a specified value.
 o charAt(int)
Returns a character at a given index in the Message.
 o getBytes()
Gives a byte reprezentation of the Message.
 o getInt(int)
Returns a integer representing two bytes starting at the given index interpreted lo, hi as a integer.
 o getString()
Gives a String reprezenting the Message.
 o length()
Gives the length of the Message.
 o readDataInputStream(DataInputStream)
Reads a message from a DataInputStream.
 o setInt(int, int)
Sets two bytes of the message, to represent a integer value as lo, hi.
 o writeDataOutputStream(DataOutputStream, Message)
Writes a message to a DataOutputStream.

Constructors

 o Message
  public Message(int len)
Constructs a null message based on a given length. No checkings are performed on parameters.
Parameters:
len - Length in bytes of the new null initialized message
 o Message
  public Message(byte oo[])
Constructs a message based on a bytes array. No checkings are performed on parameters.
Parameters:
oo[] - Bytesarray used to initialize the message
 o Message
  public Message(String ss)
Constructs a message based on a string. No checkings are performed on parameters. The the string is used only as ASCII so you will loose extra EBDIC information. (for now)
Parameters:
ss - String used to initialize the message
 o Message
  public Message(Message msg)
Constructs a message based on another message, it is just like duplicating. No checkings are performed on parameters.
Parameters:
msg - Original message to copy

Methods

 o readDataInputStream
  public static Message readDataInputStream(DataInputStream dis) throws IOException
Reads a message from a DataInputStream. Assumes the stream is open & running. No parameter checkings performed.
Parameters:
dis - The InputStream
Returns:
null if error, a new Message if ok.
Throws: IOException
If some error occured at the stream.
 o writeDataOutputStream
  public static boolean writeDataOutputStream(DataOutputStream dos,
                                              Message msg) throws IOException
Writes a message to a DataOutputStream. It might block !!! Assumes stream open & running. No parameter checkings performed.
Parameters:
msg - Message to send
Returns:
true if ok, false otherwise
Throws: IOException
If some error occured at the stream.
 o getInt
  public int getInt(int index)
Returns a integer representing two bytes starting at the given index interpreted lo, hi as a integer. No parameter checkings performed.
Parameters:
index - Start index, index of the hi byte
 o setInt
  public void setInt(int index,
                     int value)
Sets two bytes of the message, to represent a integer value as lo, hi. This is the opposite of .getInt(). No parameter checkings performed.
Parameters:
index - Index of first (hi) byte
 o charAt
  public char charAt(int index)
Returns a character at a given index in the Message. No checkings are performed on parameters.
Parameters:
index - Index in the Message
 o byteAt
  public byte byteAt(int index)
Returns a byte at a given index in the Message. No checkings are performed on parameters.
Parameters:
index - Index in the Message
 o byteAt
  public void byteAt(int index,
                     int value)
Sets a byte at a given index in the Message, with a specified value. No checkings are performed on parameters.
Parameters:
index - Index in the Message
value - Value to set
 o length
  public int length()
Gives the length of the Message.
Returns:
The length of the Message
 o getBytes
  public byte[] getBytes()
Gives a byte reprezentation of the Message.
Returns:
A byte array reprezenting the Message.
 o getString
  public String getString()
Gives a String reprezenting the Message. It just uses getBytes() to construct a ASCII String.