toolbox.parsers
Class FixedLengthParser

Package class diagram package FixedLengthParser
java.lang.Object
  extended by toolbox.parsers.FixedLengthParser

public class FixedLengthParser
extends java.lang.Object

Generic parser to parse fixed length data.


Nested Class Summary
(package private)  class FixedLengthParser.FixedParseThread
          Thread that creates TextEvent objects from a StreamTokenizer and presents the events to a TextListener instance.
 
Constructor Summary
FixedLengthParser(java.util.List fields, char padChar, java.lang.String padding, TextListener listener)
          Creates a new parser with the given List of field definitions, padding character, padding mode and listener.
FixedLengthParser(java.util.List fields, TextListener listener)
          Creates a new parser with the given List of field definitions, >empty< character for padding, the "none" padding mode and the given listener.
 
Method Summary
 char getPadChar()
          Returns the the padding character that this parser uses.
 java.lang.String getPadding()
          Returns the padding mode for this parser.
 void parse(java.io.InputStream is, boolean wait)
          Parses the given InputStream and notifies the listener of parsing events.
 void setPadChar(char padChar)
          Set the padding character for this parser.
 void setPadding(java.lang.String padding)
          Set the padding mode for this parser.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FixedLengthParser

public FixedLengthParser(java.util.List fields,
                         char padChar,
                         java.lang.String padding,
                         TextListener listener)
                  throws java.io.IOException
Creates a new parser with the given List of field definitions, padding character, padding mode and listener.

Each entry in the List must be a String in the format "start-end" where start and end are integers indicating the start and end of a specific field.

Parameters:
fields - List containing field definitions.
padChar - Character used to pad short fields.
padding - String indicating the padding mode. Valid values are "leading|trailing|none".
listener - TextListener that will receive notification of events.
Throws:
java.io.IOException

FixedLengthParser

public FixedLengthParser(java.util.List fields,
                         TextListener listener)
                  throws java.io.IOException
Creates a new parser with the given List of field definitions, >empty< character for padding, the "none" padding mode and the given listener.

Each entry in the List must be a String in the format "start-end" where start and end are integers indicating the start and end of a specific field.

Parameters:
fields - List containing field definitions.
listener - TextListener that will receive notification of events.
Throws:
java.io.IOException
Method Detail

getPadChar

public char getPadChar()
Returns the the padding character that this parser uses.

Returns:
char containing this parser's padding character.

setPadChar

public void setPadChar(char padChar)
Set the padding character for this parser.

Parameters:
padChar - New padding character.

getPadding

public java.lang.String getPadding()
Returns the padding mode for this parser.

Returns:
String indicating the padding mode.

setPadding

public void setPadding(java.lang.String padding)
Set the padding mode for this parser.

Parameters:
padding - String indicating the padding mode for this parser.

parse

public void parse(java.io.InputStream is,
                  boolean wait)
           throws java.io.IOException
Parses the given InputStream and notifies the listener of parsing events. A parsing event is generated when a newline character is encountered.

Parameters:
is - InputStream containing data to parse
wait - boolean to indicate whether not this method should wait for parsing to stop before returning.
Throws:
java.io.IOException - if a an exception occurs during parsing.