com.continuent.tungsten.common.parsing.bytes
Class ByteTranslationStateMachine

java.lang.Object
  extended by com.continuent.tungsten.common.parsing.bytes.ByteTranslationStateMachine

public class ByteTranslationStateMachine
extends java.lang.Object

Implements a finite state machine for byte string translation. The state machine uses a trie structure to track strings that have special meanings. The add(byte) method inserts a new byte "event" into the state machine for processing.

Version:
1.0
Author:
Robert Hodges

Constructor Summary
ByteTranslationStateMachine()
           
 
Method Summary
 ByteState add(byte b)
          Add a byte to the state machine and return the corresponding state.
 byte[] getSubstitute()
          Returns the last string substition.
 int getToken()
          Returns the last token value.
 void init()
          Initializes the state machine.
 boolean isSubstitute()
          Return true if a substitute string is offered.
 boolean isToken()
          Returns true if the last accepted string is a token.
 void load(byte[] value, int token, byte[] substitute, boolean escape)
          Loads a string sequence into the state machine.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ByteTranslationStateMachine

public ByteTranslationStateMachine()
Method Detail

init

public void init()
Initializes the state machine. Must be the first call to the state machine.


load

public void load(byte[] value,
                 int token,
                 byte[] substitute,
                 boolean escape)
Loads a string sequence into the state machine.

Parameters:
value - Byte array containing sequence
token - If the string is a token value, a constant equal to or greater than zero to identify the token
substitute - An alternative value that is a substitute that should be accepted instead of the parsed string
escape - True if this represents an escape sequence. The next byte after the escape sequence is accepted.

add

public ByteState add(byte b)
Add a byte to the state machine and return the corresponding state. Clients should fetch substitute strings and tokens after this call occurs.


isSubstitute

public boolean isSubstitute()
Return true if a substitute string is offered.


getSubstitute

public byte[] getSubstitute()
Returns the last string substition.


isToken

public boolean isToken()
Returns true if the last accepted string is a token.


getToken

public int getToken()
Returns the last token value.