com.sshtools.j2ssh.transport
Class SshMessage

java.lang.Object
  |
  +--com.sshtools.j2ssh.transport.SshMessage
Direct Known Subclasses:
SshMsgChannelClose, SshMsgChannelData, SshMsgChannelEOF, SshMsgChannelExtendedData, SshMsgChannelFailure, SshMsgChannelOpen, SshMsgChannelOpenConfirmation, SshMsgChannelOpenFailure, SshMsgChannelRequest, SshMsgChannelSuccess, SshMsgChannelWindowAdjust, SshMsgGlobalRequest, SshMsgKexDhInit, SshMsgKexDhReply, SshMsgRequestFailure, SshMsgRequestSuccess, SshMsgUserAuthBanner, SshMsgUserAuthFailure, SshMsgUserAuthRequest, SshMsgUserAuthSuccess

public abstract class SshMessage
extends java.lang.Object

This abstract class should be subclassed to provide message implementations for the SSH2 protocol. The message object can be constructed either from a byte array or implementation specific types. The transport layer dynamically creates the class from the registered message details and calls fromByteArray to populate before routing the message to the registered message store.

Version:
1.0
Author:
Lee David Painter ( lee@sshtools.com )

Constructor Summary
SshMessage(int messageId)
           Constructs an SshMessage used to send.
 
Method Summary
protected abstract  void constructByteArray(ByteArrayWriter baw)
           Abstract method which is called to construct the byte array returned in a call to toByteArray.
protected abstract  void constructMessage(ByteArrayReader bar)
           Abstract method which is called to construct the message from a byte array.
protected  void fromByteArray(ByteArrayReader data)
           Constructs an SshMessage from a byte array.
 int getMessageId()
           
abstract  java.lang.String getMessageName()
          Gets the messageName attribute of the SshMessage object
 byte[] toByteArray()
           Converts the message into a byte array suitable for sending.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SshMessage

public SshMessage(int messageId)

Constructs an SshMessage used to send. Subclasses classes will set their own properties typically passed to its own constructor.

Parameters:
messageId - The message Id of the message.
Method Detail

fromByteArray

protected final void fromByteArray(ByteArrayReader data)
                            throws InvalidMessageException

Constructs an SshMessage from a byte array. This method calls the abstract method constructMessage to allow subclasses classes to perform message specific construction.

Parameters:
data - The data being read.
Throws:
InvalidMessageException - Thrown when the data cannot be read.

getMessageId

public final int getMessageId()
Returns:
The message Id.

getMessageName

public abstract java.lang.String getMessageName()
Gets the messageName attribute of the SshMessage object

Returns:
The messageName value

toByteArray

public final byte[] toByteArray()
                         throws InvalidMessageException

Converts the message into a byte array suitable for sending.

Returns:
A byte array containing the message data.
Throws:
InvalidMessageException - Thrown when the byte array cannot be written.

constructByteArray

protected abstract void constructByteArray(ByteArrayWriter baw)
                                    throws InvalidMessageException

Abstract method which is called to construct the byte array returned in a call to toByteArray.

Parameters:
baw - The ByteArrayWriter instance constructing the array.
Throws:
InvalidMessageException - Thrown when the array cannot be written.

constructMessage

protected abstract void constructMessage(ByteArrayReader bar)
                                  throws InvalidMessageException

Abstract method which is called to construct the message from a byte array.

Parameters:
bar - The ByteArrayReader containing the message data.
Throws:
InvalidMessageException - Thrown when the message cannot be constructed either because the data supplied is corrupt or there are insufficient bytes.


Copyright © 2002 Sshtools.com. All Rights Reserved.