Class StreamParser

java.lang.Object
com.adaptris.adapter.edistream.utils.StreamParser

public class StreamParser extends Object
A class which enables reading and re-reading of an InputStream. Various methods of reading are supported, including Fixed Length files, simple Separated Files, Escaped Separated Files and Quoted Separated Files.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
     
    static final int
     
    static final int
     
    static final int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    StreamParser(InputStream stream, String charset)
     
    StreamParser(Reader reader, String charset)
    Creates a new instance of StreamParser which will read the contents of the supplied Reader (the reader should handle the encoding charset)
    StreamParser(String string, String charset)
    Creates a new instance of StreamParser which will read the contents of the supplied String
  • Method Summary

    Modifier and Type
    Method
    Description
     
    returns the data extracted by the last readElement() call
    void
    reads the next elemement from the source of this StreamParser according to the specified parse rule
    void
    Puts the supplied String back on the source for re-reading
    void
    setParseRule(int type, char sep)
    sets the parse rule and separator character of the element to be parsed.
    void
    setParseRule(int type, char sep, char esc)
    sets the parse rule, separator character and escape / quote character for the element to be parsed.
    void
    setParseRule(int type, int length)
    Sets the parse rule and the length of the element to be parsed.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • StreamParser

      public StreamParser(String string, String charset)
      Creates a new instance of StreamParser which will read the contents of the supplied String
    • StreamParser

      public StreamParser(InputStream stream, String charset)
    • StreamParser

      public StreamParser(Reader reader, String charset)
      Creates a new instance of StreamParser which will read the contents of the supplied Reader (the reader should handle the encoding charset)
  • Method Details

    • getCharset

      public String getCharset()
    • setParseRule

      public void setParseRule(int type, int length)
      Sets the parse rule and the length of the element to be parsed. This will be called only for Fixed Length files
      Parameters:
      type - should be StreamParser.FIXED_LENGTH
      length - the number of characters to be read
    • setParseRule

      public void setParseRule(int type, char sep)
      sets the parse rule and separator character of the element to be parsed. This is only called for simple Separated files
      Parameters:
      type - should be StreamParser.SEPARATED_STRING
      sep - the separator character
    • setParseRule

      public void setParseRule(int type, char sep, char esc)
      sets the parse rule, separator character and escape / quote character for the element to be parsed.
      e.g.
      setParseRule(ESCAPED_STRING, ',', '?') would enable parsing of [[to be?, or not to be,]]
      setParseRule(QUOTED_STRING, ',', '"') would enable parsing of [["to be, or not to be",]]

      Parameters:
      type - can be either StreamParser.ESCAPED_STRING or StreamParser.QUOTED_STRING
      sep - the separator character of this element
      esc - either the escape char of this element or the quote char
    • readElement

      public void readElement() throws Exception
      reads the next elemement from the source of this StreamParser according to the specified parse rule
      Throws:
      Exception
    • getContent

      public String getContent()
      returns the data extracted by the last readElement() call
    • rewindElement

      public void rewindElement(String string) throws IOException
      Puts the supplied String back on the source for re-reading
      Throws:
      IOException