net.kano.joscar.snaccmd
Class AbstractIcbm

java.lang.Object
  extended bySnacCommand
      extended byAbstractIcbm
Direct Known Subclasses:
AbstractChatMsgIcbm, AbstractImIcbm, AbstractRvIcbm

public abstract class AbstractIcbm
extends SnacCommand

Provides a base for all six "Inter-Client Basic Message" SNAC commands. These six commands are sending an IM, receiving an IM, sending a rendezvous packet, receiving a rendezvous packet, sending a chat room message, and receiving a chat room message. All ICBM's contain an ICBM message ID, an ICBM channel, and a channel-specific data block.


Field Summary
static int CHANNEL_CHAT
          The ICBM channel on which chat messages are sent.
static int CHANNEL_IM
          The ICBM channel on which instant messages are sent.
static int CHANNEL_RV
          The ICBM channel on which rendezvous messages are sent.
 
Fields inherited from class SnacCommand
SNACFLAG_DEFAULT
 
Constructor Summary
protected AbstractIcbm(int family, int command, long messageId, int channel)
          Creates an ICBM command with the given SNAC family and command subtype, the given ICBM message ID, and on the given ICBM channel.
protected AbstractIcbm(int family, int command, SnacPacket packet)
          Creates an ICBM command with the given SNAC family and command type, deriving ICBM fields from the contents of the given packet.
 
Method Summary
 int getChannel()
          Returns the ICBM channel on which this command resides.
protected  ByteBlock getChannelData()
          Returns the "channel-specific data" block of this ICBM.
static int getIcbmChannel(SnacPacket packet)
          Returns the ICBM channel on which the given SnacPacket resides.
 long getIcbmMessageId()
          Returns this ICBM command's message ID.
 java.lang.String toString()
           
protected abstract  void writeChannelData(java.io.OutputStream out)
          Writes the channel-specific data for this ICBM command to the given output stream.
 void writeData(java.io.OutputStream out)
          Writes this command's SNAC data block to the given stream.
 
Methods inherited from class SnacCommand
getCommand, getFamily, getFlag1, getFlag2
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CHANNEL_IM

public static final int CHANNEL_IM
The ICBM channel on which instant messages are sent.

See Also:
Constant Field Values

CHANNEL_RV

public static final int CHANNEL_RV
The ICBM channel on which rendezvous messages are sent.

See Also:
Constant Field Values

CHANNEL_CHAT

public static final int CHANNEL_CHAT
The ICBM channel on which chat messages are sent.

See Also:
Constant Field Values
Constructor Detail

AbstractIcbm

protected AbstractIcbm(int family,
                       int command,
                       SnacPacket packet)
Creates an ICBM command with the given SNAC family and command type, deriving ICBM fields from the contents of the given packet. Use getChannelData() after using this constructor to retrieve channel-specific data for this ICBM.

Parameters:
family - the SNAC family of this ICBM command
command - the SNAC command subtype of this ICBM command
packet - the packet to represent

AbstractIcbm

protected AbstractIcbm(int family,
                       int command,
                       long messageId,
                       int channel)
Creates an ICBM command with the given SNAC family and command subtype, the given ICBM message ID, and on the given ICBM channel.

Parameters:
family - the SNAC family of this ICBM command
command - the SNAC command subtype of this ICBM command
messageId - the 8-byte ICBM message ID of this command
channel - the ICBM channel of this command (should be one of CHANNEL_IM, CHANNEL_RV, CHANNEL_CHAT)
Method Detail

getIcbmChannel

public static final int getIcbmChannel(SnacPacket packet)
Returns the ICBM channel on which the given SnacPacket resides. This assumes the validity of the given packet as an ICBM packet.

Parameters:
packet - the ICBM packet whose channel number will be returned
Returns:
the ICBM channel on which the given packet was received

getIcbmMessageId

public final long getIcbmMessageId()
Returns this ICBM command's message ID. This value is used to uniquely identify ICBM responses.

Returns:
this command's ICBM message ID

getChannel

public final int getChannel()
Returns the ICBM channel on which this command resides.

Returns:
this command's ICBM channel

getChannelData

protected final ByteBlock getChannelData()
Returns the "channel-specific data" block of this ICBM. Only non-null for incoming ICBM's created using AbstractIcbm(int, int, SnacPacket).

Returns:
this ICBM's "channel-specific data"

writeData

public void writeData(java.io.OutputStream out)
               throws java.io.IOException
Description copied from class: SnacCommand
Writes this command's SNAC data block to the given stream. The SNAC data block is the data after the first ten bytes of a SNAC packet.

Specified by:
writeData in class SnacCommand
Parameters:
out - the stream to which to write the SNAC data
Throws:
java.io.IOException - if an I/O error occurs

writeChannelData

protected abstract void writeChannelData(java.io.OutputStream out)
                                  throws java.io.IOException
Writes the channel-specific data for this ICBM command to the given output stream.

Parameters:
out - the stream to write to
Throws:
java.io.IOException - if an I/O error occurs

toString

public java.lang.String toString()