Package com.adaptris.edi.util
Class StreamParser
- java.lang.Object
-
- com.adaptris.edi.util.StreamParser
-
public class StreamParser extends java.lang.ObjectA 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 intESCAPED_STRINGstatic intFIXED_LENGTHstatic intQUOTED_STRINGstatic intSEPARATED_STRING
-
Constructor Summary
Constructors Constructor Description StreamParser(java.io.InputStream stream, java.lang.String charset)StreamParser(java.lang.String string, java.lang.String charset)Creates a new instance of StreamParser which will read the contents of the supplied String
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringgetCharset()Creates a new instance of StreamParser which will read the contents of the supplied Readerjava.lang.StringgetContent()returns the data extracted by the last readElement() callvoidreadElement()reads the next elemement from the source of this StreamParser according to the specified parse rulevoidrewindElement(java.lang.String string)Puts the supplied String back on the source for re-readingvoidsetParseRule(int type, char sep)sets the parse rule and separator character of the element to be parsed.voidsetParseRule(int type, char sep, char esc)sets the parse rule, separator character and escape / quote character for the element to be parsed.voidsetParseRule(int type, int length)Sets the parse rule and the length of the element to be parsed.
-
-
-
Field Detail
-
FIXED_LENGTH
public static final int FIXED_LENGTH
- See Also:
- Constant Field Values
-
ESCAPED_STRING
public static final int ESCAPED_STRING
- See Also:
- Constant Field Values
-
QUOTED_STRING
public static final int QUOTED_STRING
- See Also:
- Constant Field Values
-
SEPARATED_STRING
public static final int SEPARATED_STRING
- See Also:
- Constant Field Values
-
-
Method Detail
-
getCharset
public java.lang.String getCharset()
Creates a new instance of StreamParser which will read the contents of the supplied Reader
-
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_LENGTHlength- 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_STRINGsep- 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_STRINGsep- the separator character of this elementesc- either the escape char of this element or the quote char
-
readElement
public void readElement() throws java.lang.Exceptionreads the next elemement from the source of this StreamParser according to the specified parse rule- Throws:
java.lang.Exception
-
getContent
public java.lang.String getContent()
returns the data extracted by the last readElement() call
-
rewindElement
public void rewindElement(java.lang.String string) throws java.io.IOExceptionPuts the supplied String back on the source for re-reading- Throws:
java.io.IOException
-
-