com.superhac.JXBStreamer.Core
Class XBMSPEncoderDecoder

java.lang.Object
  extended by com.superhac.JXBStreamer.Core.XBMSPEncoderDecoder

public class XBMSPEncoderDecoder
extends java.lang.Object

This handles all the XMBSP packet Decoding and Encoding. This is used by the XBMSPServerMessageHandler's to decode and code messages.

The protocol is documented here.

More information can be found at Superhac.com


Field Summary
protected static java.lang.String SERVER_VERSION
           
protected static byte XBMSP_ERROR_AUTHENTICATION_FAILED
           
protected static byte XBMSP_ERROR_AUTHENTICATION_NEEDED
           
protected static byte XBMSP_ERROR_FAILURE
           
protected static byte XBMSP_ERROR_ILLEGAL_SEEK
           
protected static byte XBMSP_ERROR_INVALID_FILE
           
protected static byte XBMSP_ERROR_INVALID_HANDLE
           
protected static byte XBMSP_ERROR_INVALID_OPTION_VALUE
           
protected static byte XBMSP_ERROR_NO_SUCH_FILE
           
protected static byte XBMSP_ERROR_OK
           
protected static byte XBMSP_ERROR_OPEN_FAILED
           
protected static byte XBMSP_ERROR_OPTION_IS_READ_ONLY
           
protected static byte XBMSP_ERROR_TOO_LONG_READ
           
protected static byte XBMSP_ERROR_TOO_MANY_OPEN_FILES
           
protected static byte XBMSP_ERROR_UNSUPPORTED
           
protected static byte XBMSP_FILE_SEEK_TYPE_BCKFROMCUR
           
protected static byte XBMSP_FILE_SEEK_TYPE_BCKFROMEND
           
protected static byte XBMSP_FILE_SEEK_TYPE_FWDFROMBEG
           
protected static byte XBMSP_FILE_SEEK_TYPE_FWDFROMCUR
           
protected static byte XBMSP_PACKET_AUTHENTICATE
           
protected static byte XBMSP_PACKET_AUTHENTICATION_CONTINUE
           
protected static byte XBMSP_PACKET_AUTHENTICATION_INIT
           
protected static byte XBMSP_PACKET_CLOSE
           
protected static byte XBMSP_PACKET_CLOSE_ALL
           
protected static byte XBMSP_PACKET_ERROR
           
protected static byte XBMSP_PACKET_FILE_CONTENTS
           
protected static byte XBMSP_PACKET_FILE_DATA
           
protected static byte XBMSP_PACKET_FILE_INFO
           
protected static byte XBMSP_PACKET_FILE_OPEN
           
protected static byte XBMSP_PACKET_FILE_READ
           
protected static byte XBMSP_PACKET_FILE_SEEK
           
protected static byte XBMSP_PACKET_FILELIST_OPEN
           
protected static byte XBMSP_PACKET_FILELIST_READ
           
protected static byte XBMSP_PACKET_HANDLE
           
protected static byte XBMSP_PACKET_NULL
           
protected static byte XBMSP_PACKET_OK
           
protected static byte XBMSP_PACKET_SERVER_DISCOVERY_QUERY
          Packet types (e.g.
protected static byte XBMSP_PACKET_SERVER_DISCOVERY_REPLY
           
protected static byte XBMSP_PACKET_SET_CONFIGURATION_OPTION
           
protected static byte XBMSP_PACKET_SETCWD
           
protected static byte XBMSP_PACKET_UPCWD
           
 
Constructor Summary
protected XBMSPEncoderDecoder()
           
 
Method Summary
protected  void decodepacket(java.nio.ByteBuffer buff)
          Takes the socket buffer thats passed in and decodes the message.
protected  XBMSPEncoderDecoder encodePacketError(byte errorCode, java.lang.String errorMessage)
          Encodes a packet ERROR response to this instance of XBMSPEncoderDecoder.
protected  XBMSPEncoderDecoder encodePacketFileContents(java.nio.ByteBuffer data)
          Encodes a packet encodePacketFileContents response to this instance of XBMSPEncoderDecoder.
protected  XBMSPEncoderDecoder encodePacketFileData(java.lang.String name, java.lang.String data)
          Encodes a packet PacketFileData response to this instance of XBMSPEncoderDecoder.
protected  XBMSPEncoderDecoder encodePacketHandle(int handle)
          Encodes a packet PacketHandle response to this instance of XBMSPEncoderDecoder.
protected  XBMSPEncoderDecoder encodePacketOk()
          Encodes a packet OK response to this instance of XBMSPEncoderDecoder.
protected  java.nio.ByteBuffer getPacket()
          Call this after the message is ready to be transmitted.
protected  byte getPayloadByte()
          Gets the first byte from the payload..
protected  byte[] getPayloadData()
          Gets the first byte[] from the payload..
protected  int getPayloadInt()
          Gets the first Int from the payload..
protected  int getPayloadInt2()
          Gets the second Int from the payload..
protected  long getPayloadInt64()
          Gets the first long(INT64) from the payload..
protected  java.lang.String getPayloadString()
          Gets the first String from the payload..
protected  java.lang.String getPayloadString2()
          Gets the Second String from the payload..
protected  byte getType()
          Returns the packet type (type field)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SERVER_VERSION

protected static final java.lang.String SERVER_VERSION
See Also:
Constant Field Values

XBMSP_PACKET_NULL

protected static final byte XBMSP_PACKET_NULL
See Also:
Constant Field Values

XBMSP_PACKET_SETCWD

protected static final byte XBMSP_PACKET_SETCWD
See Also:
Constant Field Values

XBMSP_PACKET_FILELIST_OPEN

protected static final byte XBMSP_PACKET_FILELIST_OPEN
See Also:
Constant Field Values

XBMSP_PACKET_FILELIST_READ

protected static final byte XBMSP_PACKET_FILELIST_READ
See Also:
Constant Field Values

XBMSP_PACKET_FILE_INFO

protected static final byte XBMSP_PACKET_FILE_INFO
See Also:
Constant Field Values

XBMSP_PACKET_FILE_OPEN

protected static final byte XBMSP_PACKET_FILE_OPEN
See Also:
Constant Field Values

XBMSP_PACKET_FILE_READ

protected static final byte XBMSP_PACKET_FILE_READ
See Also:
Constant Field Values

XBMSP_PACKET_FILE_SEEK

protected static final byte XBMSP_PACKET_FILE_SEEK
See Also:
Constant Field Values

XBMSP_PACKET_CLOSE

protected static final byte XBMSP_PACKET_CLOSE
See Also:
Constant Field Values

XBMSP_PACKET_CLOSE_ALL

protected static final byte XBMSP_PACKET_CLOSE_ALL
See Also:
Constant Field Values

XBMSP_PACKET_SET_CONFIGURATION_OPTION

protected static final byte XBMSP_PACKET_SET_CONFIGURATION_OPTION
See Also:
Constant Field Values

XBMSP_PACKET_AUTHENTICATION_INIT

protected static final byte XBMSP_PACKET_AUTHENTICATION_INIT
See Also:
Constant Field Values

XBMSP_PACKET_AUTHENTICATE

protected static final byte XBMSP_PACKET_AUTHENTICATE
See Also:
Constant Field Values

XBMSP_PACKET_UPCWD

protected static final byte XBMSP_PACKET_UPCWD
See Also:
Constant Field Values

XBMSP_PACKET_OK

protected static final byte XBMSP_PACKET_OK
See Also:
Constant Field Values

XBMSP_PACKET_ERROR

protected static final byte XBMSP_PACKET_ERROR
See Also:
Constant Field Values

XBMSP_PACKET_HANDLE

protected static final byte XBMSP_PACKET_HANDLE
See Also:
Constant Field Values

XBMSP_PACKET_FILE_DATA

protected static final byte XBMSP_PACKET_FILE_DATA
See Also:
Constant Field Values

XBMSP_PACKET_FILE_CONTENTS

protected static final byte XBMSP_PACKET_FILE_CONTENTS
See Also:
Constant Field Values

XBMSP_PACKET_AUTHENTICATION_CONTINUE

protected static final byte XBMSP_PACKET_AUTHENTICATION_CONTINUE
See Also:
Constant Field Values

XBMSP_PACKET_SERVER_DISCOVERY_QUERY

protected static final byte XBMSP_PACKET_SERVER_DISCOVERY_QUERY
Packet types (e.g. type field) for Server discovery protocol

See Also:
Constant Field Values

XBMSP_PACKET_SERVER_DISCOVERY_REPLY

protected static final byte XBMSP_PACKET_SERVER_DISCOVERY_REPLY
See Also:
Constant Field Values

XBMSP_ERROR_OK

protected static final byte XBMSP_ERROR_OK
See Also:
Constant Field Values

XBMSP_ERROR_FAILURE

protected static final byte XBMSP_ERROR_FAILURE
See Also:
Constant Field Values

XBMSP_ERROR_UNSUPPORTED

protected static final byte XBMSP_ERROR_UNSUPPORTED
See Also:
Constant Field Values

XBMSP_ERROR_NO_SUCH_FILE

protected static final byte XBMSP_ERROR_NO_SUCH_FILE
See Also:
Constant Field Values

XBMSP_ERROR_INVALID_FILE

protected static final byte XBMSP_ERROR_INVALID_FILE
See Also:
Constant Field Values

XBMSP_ERROR_INVALID_HANDLE

protected static final byte XBMSP_ERROR_INVALID_HANDLE
See Also:
Constant Field Values

XBMSP_ERROR_OPEN_FAILED

protected static final byte XBMSP_ERROR_OPEN_FAILED
See Also:
Constant Field Values

XBMSP_ERROR_TOO_MANY_OPEN_FILES

protected static final byte XBMSP_ERROR_TOO_MANY_OPEN_FILES
See Also:
Constant Field Values

XBMSP_ERROR_TOO_LONG_READ

protected static final byte XBMSP_ERROR_TOO_LONG_READ
See Also:
Constant Field Values

XBMSP_ERROR_ILLEGAL_SEEK

protected static final byte XBMSP_ERROR_ILLEGAL_SEEK
See Also:
Constant Field Values

XBMSP_ERROR_OPTION_IS_READ_ONLY

protected static final byte XBMSP_ERROR_OPTION_IS_READ_ONLY
See Also:
Constant Field Values

XBMSP_ERROR_INVALID_OPTION_VALUE

protected static final byte XBMSP_ERROR_INVALID_OPTION_VALUE
See Also:
Constant Field Values

XBMSP_ERROR_AUTHENTICATION_NEEDED

protected static final byte XBMSP_ERROR_AUTHENTICATION_NEEDED
See Also:
Constant Field Values

XBMSP_ERROR_AUTHENTICATION_FAILED

protected static final byte XBMSP_ERROR_AUTHENTICATION_FAILED
See Also:
Constant Field Values

XBMSP_FILE_SEEK_TYPE_FWDFROMBEG

protected static final byte XBMSP_FILE_SEEK_TYPE_FWDFROMBEG
See Also:
Constant Field Values

XBMSP_FILE_SEEK_TYPE_BCKFROMEND

protected static final byte XBMSP_FILE_SEEK_TYPE_BCKFROMEND
See Also:
Constant Field Values

XBMSP_FILE_SEEK_TYPE_FWDFROMCUR

protected static final byte XBMSP_FILE_SEEK_TYPE_FWDFROMCUR
See Also:
Constant Field Values

XBMSP_FILE_SEEK_TYPE_BCKFROMCUR

protected static final byte XBMSP_FILE_SEEK_TYPE_BCKFROMCUR
See Also:
Constant Field Values
Constructor Detail

XBMSPEncoderDecoder

protected XBMSPEncoderDecoder()
Method Detail

getPacket

protected java.nio.ByteBuffer getPacket()
Call this after the message is ready to be transmitted.

Returns:
a buffer containing the encoded packet.

getType

protected byte getType()
Returns the packet type (type field)

Returns:

decodepacket

protected void decodepacket(java.nio.ByteBuffer buff)
Takes the socket buffer thats passed in and decodes the message.

Parameters:
buff - the Buffer from the socket.

encodePacketOk

protected XBMSPEncoderDecoder encodePacketOk()
Encodes a packet OK response to this instance of XBMSPEncoderDecoder. An encoded message is always based on a message recieved from the client. Hence we use the orginal XBMSPEncoderDecoder instance of the recieved message to encode the response.

Returns:
a new XBMSPEncoderDecoder with the response packet.

encodePacketError

protected XBMSPEncoderDecoder encodePacketError(byte errorCode,
                                                java.lang.String errorMessage)
Encodes a packet ERROR response to this instance of XBMSPEncoderDecoder. An encoded message is always based on a message recieved from the client. Hence we use the orginal XBMSPEncoderDecoder instance of the recieved message to encode the response.

Parameters:
errorCode - the error code as defined by the XBMSP protocol.
errorMessage - an optional TEXT message
Returns:
a new XBMSPEncoderDecoder with the response packet.

encodePacketHandle

protected XBMSPEncoderDecoder encodePacketHandle(int handle)
Encodes a packet PacketHandle response to this instance of XBMSPEncoderDecoder. An encoded message is always based on a message recieved from the client. Hence we use the orginal XBMSPEncoderDecoder instance of the recieved message to encode the response.

Parameters:
handle - the handle number of the file or directory
Returns:
a new XBMSPEncoderDecoder with the response packet.

encodePacketFileData

protected XBMSPEncoderDecoder encodePacketFileData(java.lang.String name,
                                                   java.lang.String data)
Encodes a packet PacketFileData response to this instance of XBMSPEncoderDecoder. An encoded message is always based on a message recieved from the client. Hence we use the orginal XBMSPEncoderDecoder instance of the recieved message to encode the response.

Parameters:
name - The name of the file or handle(file.getName())
data - The XML encoded String with the file data. (e.g. file size, accessTime, etc..)
Returns:
a new XBMSPEncoderDecoder with the response packet.

encodePacketFileContents

protected XBMSPEncoderDecoder encodePacketFileContents(java.nio.ByteBuffer data)
Encodes a packet encodePacketFileContents response to this instance of XBMSPEncoderDecoder. An encoded message is always based on a message recieved from the client. Hence we use the orginal XBMSPEncoderDecoder instance of the recieved message to encode the response.

Parameters:
data - the raw file data for the request
Returns:
a new XBMSPEncoderDecoder with the response packet.

getPayloadByte

protected byte getPayloadByte()
Gets the first byte from the payload.. (message data section)

Returns:

getPayloadData

protected byte[] getPayloadData()
Gets the first byte[] from the payload.. (message data section)

Returns:

getPayloadInt

protected int getPayloadInt()
Gets the first Int from the payload.. (message data section)

Returns:

getPayloadInt2

protected int getPayloadInt2()
Gets the second Int from the payload.. (message data section)

Returns:

getPayloadInt64

protected long getPayloadInt64()
Gets the first long(INT64) from the payload.. (message data section)

Returns:

getPayloadString

protected java.lang.String getPayloadString()
Gets the first String from the payload.. (message data section)

Returns:

getPayloadString2

protected java.lang.String getPayloadString2()
Gets the Second String from the payload.. (message data section)

Returns: