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

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

public class CharacterTranslationBuffer
extends java.lang.Object

Implements a translation buffer for complex byte strings that allows clients to translate parts of the buffer directly to Unicode and to substitute other parts with different values.

Version:
1.0
Author:
Jussi-Pekka Kurikka

Constructor Summary
CharacterTranslationBuffer()
           
 
Method Summary
 void append(java.lang.String s)
          Append a string to the output without affecting pending bytes.
 void appendAndClearPending(java.lang.String s)
          Append a string to the output and clear pending bytes.
 void backoff(int goBack)
          Backup current pointer or or more bytes.
 java.lang.String getOutput()
          Returns the output value as a Java String.
 boolean hasNext()
          Returns true if there are more bytes to read in the buffer.
 boolean isComplete()
          Returns true if we have processed all bytes and the output is ready.
 void load(byte[] input, int offset, int length, java.lang.String charset)
          Initialize for translation.
 byte next()
          Returns the next byte to process.
 void translateAndAppendPending(int backoff)
          Translate pending bytes using selected character set.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CharacterTranslationBuffer

public CharacterTranslationBuffer()
Method Detail

load

public void load(byte[] input,
                 int offset,
                 int length,
                 java.lang.String charset)
Initialize for translation.

Parameters:
input - Byte buffer that is to be translated
offset - Starting offset in buffer. 0 is the beginning.
length - Length of the buffer. 0 denotes an empty buffer.
charset - Name of character used to encode characters.

next

public byte next()
Returns the next byte to process.


backoff

public void backoff(int goBack)
Backup current pointer or or more bytes.


hasNext

public boolean hasNext()
Returns true if there are more bytes to read in the buffer.


isComplete

public boolean isComplete()
Returns true if we have processed all bytes and the output is ready.


append

public void append(java.lang.String s)
Append a string to the output without affecting pending bytes.


appendAndClearPending

public void appendAndClearPending(java.lang.String s)
Append a string to the output and clear pending bytes.


translateAndAppendPending

public void translateAndAppendPending(int backoff)
                               throws java.io.UnsupportedEncodingException
Translate pending bytes using selected character set. Bytes are translated up to current position minus the backoff value.

Throws:
java.io.UnsupportedEncodingException

getOutput

public java.lang.String getOutput()
Returns the output value as a Java String.