xmlBlaster 2.2.0 client API

org.xmlBlaster.util.xbformat
Class XbfParser

java.lang.Object
  extended by org.xmlBlaster.util.xbformat.XbfParser
All Implemented Interfaces:
I_MsgInfoParser

public class XbfParser
extends java.lang.Object
implements I_MsgInfoParser

XbfParser class for raw socket/email messages.
This class creates and parses raw byte[] messages which can be used to transfer over a socket connection.
XbfParser instances may be reused, but are NOT reentrant (there are many 'global' variables)
Please read the requirement specification protocol.socket

  msgLen[10] flag[6] requestId methodName sessionId  lenUnzipped  userData  checkSum[10]
  +---------+-------+------ -*----------*-----------*-----------*-----------+----------+


  The 'userData' consists of 0-n of these:

  qos      key    len   content
  +-----*---------*-----*----------+


  Examples, '*' marks a null byte and '|' is just to show the boundary (is not part of the message):

  Testing qos/key/content
  |        83**I**17711*publish*oxf6hZs****11*Hello world|

  Testing qos/key
  |        70**I**17711*get*oxf6hZs****0*|

  Testing publish return with qos
  |        48**R**17711*publish*oxf6hZs****0*|

  Testing nothing
  |        38**I**17711*get*oxf6hZs****0*|

  Testing ping:
  |        29**I**11*ping*****0*|

  Testing XmlBlasterException
  |        76**E**17711*get*oxf6hZs**XbfParser*An XmlBlasterException test only*0*|

  Testing qos/key/content return value
  |        85**R**17711*publish*****20*Hello world response|

  Testing a QoS return value
  |        58**R**17711*get*****0*|

  Testing two qos/key/content
  |       100**I**17711*publish*oxf6hZs****6*Hello1**6*Hello2|
 

Author:
xmlBlaster@marcelruff.info
See Also:
The protocol.socket requirement

Field Summary
static byte CHECKSUM_ADLER_BYTE
           
static byte COMPRESSED_GZIP_BYTE
           
static java.lang.String EMPTY_STRING
           
static int FLAG_FIELD_LEN
           
static int MAX_STRING_LEN
           
static int NUM_FIELD_LEN
           
static byte VERSION_1_BYTE
           
static java.lang.String XBFORMAT_EXTENSION
           
static java.lang.String XBFORMAT_MIMETYPE
           
static java.lang.String XBFORMAT_ZLIB_EXTENSION
           
static java.lang.String XBFORMAT_ZLIB_MIMETYPE
           
 
Constructor Summary
XbfParser()
           
 
Method Summary
static java.lang.String createLiteral(byte[] arr)
          Get the raw messages as a string, for tests and for dumping only
 byte[] createRawMsg(MsgInfo msgInfo)
          Returns a raw data string.
 java.lang.String getExtension(boolean isCompressed)
          Get a specific extension for this format.
 java.lang.String getMimetype(boolean isCompressed)
          Get a specific extension for this format.
 void init(Global glob, I_ProgressListener progressListener, I_PluginConfig pluginConfig)
          Is guaranteed to be called by the MsgInfoParserFactory after construction.
 MsgInfo[] parse(java.io.InputStream in)
          This parses the raw message from an InputStream (typically from a socket).
 byte[] toByte(org.xmlBlaster.util.xbformat.XbfParser.Buf buf)
          Reads the binary content of a message.
 java.lang.String toLiteral(byte[] arr)
          Get the raw messages as a string, for tests and for dumping only.
 java.lang.String toLiteral(MsgInfo msgInfo)
          Get the raw messages as a string, for tests and for dumping only
 long toLong0(org.xmlBlaster.util.xbformat.XbfParser.Buf buf, long defaultVal)
          Converts bytes from byte[] until \0 to a long
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NUM_FIELD_LEN

public static final int NUM_FIELD_LEN
See Also:
Constant Field Values

FLAG_FIELD_LEN

public static final int FLAG_FIELD_LEN
See Also:
Constant Field Values

MAX_STRING_LEN

public static final int MAX_STRING_LEN
See Also:
Constant Field Values

EMPTY_STRING

public static final java.lang.String EMPTY_STRING
See Also:
Constant Field Values

CHECKSUM_ADLER_BYTE

public static final byte CHECKSUM_ADLER_BYTE
See Also:
Constant Field Values

COMPRESSED_GZIP_BYTE

public static final byte COMPRESSED_GZIP_BYTE
See Also:
Constant Field Values

VERSION_1_BYTE

public static final byte VERSION_1_BYTE
See Also:
Constant Field Values

XBFORMAT_EXTENSION

public static final java.lang.String XBFORMAT_EXTENSION
See Also:
Constant Field Values

XBFORMAT_ZLIB_EXTENSION

public static final java.lang.String XBFORMAT_ZLIB_EXTENSION
See Also:
Constant Field Values

XBFORMAT_MIMETYPE

public static final java.lang.String XBFORMAT_MIMETYPE
See Also:
Constant Field Values

XBFORMAT_ZLIB_MIMETYPE

public static final java.lang.String XBFORMAT_ZLIB_MIMETYPE
See Also:
Constant Field Values
Constructor Detail

XbfParser

public XbfParser()
Method Detail

init

public void init(Global glob,
                 I_ProgressListener progressListener,
                 I_PluginConfig pluginConfig)
Description copied from interface: I_MsgInfoParser
Is guaranteed to be called by the MsgInfoParserFactory after construction.

Specified by:
init in interface I_MsgInfoParser
pluginConfig - Can be null

getMimetype

public final java.lang.String getMimetype(boolean isCompressed)
Description copied from interface: I_MsgInfoParser
Get a specific extension for this format.

Specified by:
getMimetype in interface I_MsgInfoParser
Parameters:
isCompressed - true/false
Returns:
XBFORMAT_MIMETYPE = "application/xmlBlaster-xbf"; XBFORMAT_ZLIB_MIMETYPE = "application/xmlBlaster-xbfz";

getExtension

public final java.lang.String getExtension(boolean isCompressed)
Description copied from interface: I_MsgInfoParser
Get a specific extension for this format.

Specified by:
getExtension in interface I_MsgInfoParser
Parameters:
isCompressed - true/false
Returns:
XBFORMAT_EXTENSION = ".xbf"; XBFORMAT_ZLIB_EXTENSION = ".xbfz";

parse

public final MsgInfo[] parse(java.io.InputStream in)
                      throws java.io.IOException,
                             java.lang.IllegalArgumentException
This parses the raw message from an InputStream (typically from a socket). Use the get...() methods to access the data.

This method blocks until a message arrives

Specified by:
parse in interface I_MsgInfoParser
Parameters:
in - The raw, serialized data
Returns:
Guaranteed to be always an array of length=1
Throws:
java.io.IOException
java.lang.IllegalArgumentException

createRawMsg

public final byte[] createRawMsg(MsgInfo msgInfo)
                          throws XmlBlasterException
Returns a raw data string.
  msgLen[10] flag[6] requestId methodName sessionId  lenUnzipped  userData  checkSum[10]
  +---------+-------+------ -*----------*-----------*-----------*-----------+----------+


  The 'userData' consists of 0-n of these:

  qos      key    len   content
  +-----*---------*-----*----------+

  An example is ('*' marks a null byte):

  "        83**I**17711*publish*oxf6hZs****11*Hello world"

 

Specified by:
createRawMsg in interface I_MsgInfoParser
Returns:
The serializd message
Throws:
XmlBlasterException

toByte

public final byte[] toByte(org.xmlBlaster.util.xbformat.XbfParser.Buf buf)
                    throws java.io.IOException
Reads the binary content of a message. First we parse the long value which holds the content length, than we retrieve the binary content.

Throws:
java.io.IOException

toLong0

public final long toLong0(org.xmlBlaster.util.xbformat.XbfParser.Buf buf,
                          long defaultVal)
                   throws java.io.IOException
Converts bytes from byte[] until \0 to a long

Throws:
java.io.IOException

toLiteral

public final java.lang.String toLiteral(MsgInfo msgInfo)
                                 throws XmlBlasterException
Get the raw messages as a string, for tests and for dumping only

Specified by:
toLiteral in interface I_MsgInfoParser
Returns:
The stringified message, null bytes are replaced by '*'
Throws:
XmlBlasterException

toLiteral

public final java.lang.String toLiteral(byte[] arr)
Description copied from interface: I_MsgInfoParser
Get the raw messages as a string, for tests and for dumping only.

Specified by:
toLiteral in interface I_MsgInfoParser
Parameters:
arr - The raw blob
Returns:
The stringified message, null bytes are replaced by '*'

createLiteral

public static final java.lang.String createLiteral(byte[] arr)
Get the raw messages as a string, for tests and for dumping only

Returns:
The stringified message, null bytes are replaced by '*'

xmlBlaster 2.2.0 client API

Copyright © 1999-2014 The xmlBlaster.org contributers.