Class StreamParser
java.lang.Object
com.adaptris.adapter.edistream.utils.StreamParser
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
FieldsModifier and TypeFieldDescriptionstatic final int
static final int
static final int
static final int
-
Constructor Summary
ConstructorsConstructorDescriptionStreamParser
(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 TypeMethodDescriptionreturns the data extracted by the last readElement() callvoid
reads the next elemement from the source of this StreamParser according to the specified parse rulevoid
rewindElement
(String string) Puts the supplied String back on the source for re-readingvoid
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.
-
Field Details
-
FIXED_LENGTH
public static final int FIXED_LENGTH- See Also:
-
ESCAPED_STRING
public static final int ESCAPED_STRING- See Also:
-
QUOTED_STRING
public static final int QUOTED_STRING- See Also:
-
SEPARATED_STRING
public static final int SEPARATED_STRING- See Also:
-
-
Constructor Details
-
StreamParser
Creates a new instance of StreamParser which will read the contents of the supplied String -
StreamParser
-
StreamParser
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
-
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
reads the next elemement from the source of this StreamParser according to the specified parse rule- Throws:
Exception
-
getContent
returns the data extracted by the last readElement() call -
rewindElement
Puts the supplied String back on the source for re-reading- Throws:
IOException
-