xmlBlaster 2.2.0 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

Nested Class Summary
private  class XbfParser.Buf
           
 
Field Summary
private  XbfParser.Buf buf
           
static byte CHECKSUM_ADLER_BYTE
           
private  long checkSumResult
           
static byte COMPRESSED_GZIP_BYTE
           
static java.lang.String EMPTY_STRING
           
private static byte[] EMPTY10
           
private  byte[] first10
           
static int FLAG_FIELD_LEN
           
private  Global glob
           
private  long lenUnzipped
           
private static java.util.logging.Logger log
           
static int MAX_STRING_LEN
           
private  int maxMsgLength
           
private static java.lang.String ME
           
private static byte NULL_BYTE
           
static int NUM_FIELD_LEN
           
private  I_ProgressListener progressListener
          If not null somebody wants to be notified about the current bytes send over socket
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.
private  void initialize()
           
private  java.lang.String niceAndShort(java.lang.String tmp)
           
 MsgInfo[] parse(java.io.InputStream in)
          This parses the raw message from an InputStream (typically from a socket).
private  XbfParser.Buf readOneMsg(MsgInfo msgInfo, java.io.InputStream in)
          Blocks on socket until a complete message is read.
 byte[] toByte(XbfParser.Buf buf)
          Reads the binary content of a message.
private  int toInt0(XbfParser.Buf buf, int defaultVal)
          Converts bytes from byte[] until \0 to an int
 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(XbfParser.Buf buf, long defaultVal)
          Converts bytes from byte[] until \0 to a long
private  java.lang.String toString(XbfParser.Buf buf)
          Extracts string until next null byte '\0'
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ME

private static final java.lang.String ME
See Also:
Constant Field Values

glob

private Global glob

log

private static java.util.logging.Logger log

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

EMPTY10

private static final byte[] EMPTY10

NULL_BYTE

private static final byte NULL_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

buf

private XbfParser.Buf buf

first10

private byte[] first10

lenUnzipped

private long lenUnzipped

checkSumResult

private long checkSumResult

maxMsgLength

private int maxMsgLength

progressListener

private I_ProgressListener progressListener
If not null somebody wants to be notified about the current bytes send over socket

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

initialize

private void initialize()

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";

readOneMsg

private final XbfParser.Buf readOneMsg(MsgInfo msgInfo,
                                       java.io.InputStream in)
                                throws java.io.IOException
Blocks on socket until a complete message is read.

Returns:
A complete message in a byte[]. NOTE: The first 10 bytes are not initialized.
null: An empty message which only contains the header 10 bytes
Throws:
java.io.IOException

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(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(XbfParser.Buf buf,
                          long defaultVal)
                   throws java.io.IOException
Converts bytes from byte[] until \0 to a long

Throws:
java.io.IOException

toInt0

private final int toInt0(XbfParser.Buf buf,
                         int defaultVal)
                  throws java.io.IOException
Converts bytes from byte[] until \0 to an int

Throws:
java.io.IOException

niceAndShort

private java.lang.String niceAndShort(java.lang.String tmp)

toString

private final java.lang.String toString(XbfParser.Buf buf)
                                 throws java.io.IOException
Extracts string until next null byte '\0'

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 API

Copyright © 1999-2014 The xmlBlaster.org contributers.