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
-
Message(byte[])
- Constructs a message based on a bytes array.
-
Message(int)
- Constructs a null message based on a given length.
-
Message(Message)
- Constructs a message based on another message, it is just like duplicating.
-
Message(String)
- Constructs a message based on a string.
-
byteAt(int)
- Returns a byte at a given index in the Message.
-
byteAt(int, int)
- Sets a byte at a given index in the Message, with a specified value.
-
charAt(int)
- Returns a character at a given index in the Message.
-
getBytes()
- Gives a byte reprezentation of the Message.
-
getInt(int)
- Returns a integer representing two bytes starting at the given index
interpreted lo, hi as a integer.
-
getString()
- Gives a String reprezenting the Message.
-
length()
- Gives the length of the Message.
-
readDataInputStream(DataInputStream)
- Reads a message from a DataInputStream.
-
setInt(int, int)
- Sets two bytes of the message, to represent a integer value as lo, hi.
-
writeDataOutputStream(DataOutputStream, Message)
-
Writes a message to a DataOutputStream.
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
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
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
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
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.
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.
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
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
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
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
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
length
public int length()
- Gives the length of the Message.
- Returns:
- The length of the Message
getBytes
public byte[] getBytes()
- Gives a byte reprezentation of the Message.
- Returns:
- A byte array reprezenting the Message.
getString
public String getString()
- Gives a String reprezenting the Message.
It just uses getBytes() to construct a ASCII String.