inf1010.pusle.chat
Class ChatUtilities

java.lang.Object
  extended by inf1010.pusle.chat.ChatUtilities

public class ChatUtilities
extends java.lang.Object

A utility class containing constants for the chat system.


Field Summary
static java.nio.charset.Charset charset
          The character set used by the chat system (UTF-8).
static int DATA_INDEX
          Packet indices.
static int DEFAULT_PORT
          The default port number used by the chat programs.
static byte DISCONNECT
          Packet types.
static int HEADER_LENGTH
          Number of bytes in a packet header.
static byte INVALID_PACKET
          Packet types.
static byte INVALID_USERNAME
          Packet types.
static int LENGTH_INDEX
          Packet indices.
static byte LOGIN
          Packet types.
static int MAX_LENGTH
          The maximum length of data sent in a packet.
static byte MESSAGE
          Packet types.
static byte MESSAGE_FROM
          Packet types.
static byte NEW_USER
          Packet types.
static int TYPE_INDEX
          Packet indices.
static byte USER_LEFT
          Packet types.
static byte USER_LIST
          Packet types.
static byte WELCOME
          Packet types.
 
Constructor Summary
ChatUtilities()
           
 
Method Summary
static Message recvMessage(java.io.InputStream in)
          Receives a message from an input stream.
static boolean sendMessage(byte type, java.lang.String data, java.io.OutputStream out)
          Sends data on an output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_PORT

public static final int DEFAULT_PORT
The default port number used by the chat programs.

See Also:
Constant Field Values

HEADER_LENGTH

public static final int HEADER_LENGTH
Number of bytes in a packet header.

See Also:
Constant Field Values

MAX_LENGTH

public static final int MAX_LENGTH
The maximum length of data sent in a packet.

See Also:
Constant Field Values

charset

public static final java.nio.charset.Charset charset
The character set used by the chat system (UTF-8).


TYPE_INDEX

public static final int TYPE_INDEX
Packet indices.

See Also:
Constant Field Values

LENGTH_INDEX

public static final int LENGTH_INDEX
Packet indices.

See Also:
Constant Field Values

DATA_INDEX

public static final int DATA_INDEX
Packet indices.

See Also:
Constant Field Values

LOGIN

public static final byte LOGIN
Packet types.

See Also:
Constant Field Values

WELCOME

public static final byte WELCOME
Packet types.

See Also:
Constant Field Values

USER_LIST

public static final byte USER_LIST
Packet types.

See Also:
Constant Field Values

NEW_USER

public static final byte NEW_USER
Packet types.

See Also:
Constant Field Values

USER_LEFT

public static final byte USER_LEFT
Packet types.

See Also:
Constant Field Values

DISCONNECT

public static final byte DISCONNECT
Packet types.

See Also:
Constant Field Values

MESSAGE_FROM

public static final byte MESSAGE_FROM
Packet types.

See Also:
Constant Field Values

MESSAGE

public static final byte MESSAGE
Packet types.

See Also:
Constant Field Values

INVALID_USERNAME

public static final byte INVALID_USERNAME
Packet types.

See Also:
Constant Field Values

INVALID_PACKET

public static final byte INVALID_PACKET
Packet types.

See Also:
Constant Field Values
Constructor Detail

ChatUtilities

public ChatUtilities()
Method Detail

sendMessage

public static boolean sendMessage(byte type,
                                  java.lang.String data,
                                  java.io.OutputStream out)
                           throws java.io.IOException
Sends data on an output stream.

Parameters:
type - the type of message to send to the server.
data - the data to send with the message.
out - the output stream to send data to.
Returns:
false if the data was too long.
Throws:
java.io.IOException - if anything goes wrong with sending the data.

recvMessage

public static Message recvMessage(java.io.InputStream in)
                           throws java.io.IOException
Receives a message from an input stream.

Parameters:
in - the input stream to receive the message from.
Returns:
a Message representing the packet.
Throws:
java.io.IOException - if anything goes wrong with receiving the data.