|
BeanIO 2.0.4 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.beanio.stream.delimited.DelimitedReader
public class DelimitedReader
A DelimitedReader is used to parse delimited flat files into records of String arrays. Records must be terminated by a single configurable character, or by default, any of the following: line feed (LF), carriage return (CR), or CRLF combination. And fields that make up a record must be delimited by a single configurable character.
If an escape character is configured, the delimiting character can be be escaped in a field by placing the escape character immediately before the delimiter. The escape character may also be used to escape itself. For example, using a comma delimiter and backslash escape:
Field1,Field2\,Field3,Field\\4,Field\5The record would be parsed as "Field1", "Field2,Field3", "Field\4", "Field\5"
Additionally, if a record may span multiple lines, a single line continuation character can be configured. The line continuation character must immediately precede the record termination character. For example, using a comma delimiter and backslash line continuation character:
Field1,Field2\ Field3The 2 lines would be parsed as a single record with values "Field1", "Field2", "Field3".
The same character can be used for line continuation and escaping, but neither can match the delimiter.
Constructor Summary | |
---|---|
DelimitedReader(Reader in)
Constructs a new DelimitedReader using a tab character for the field delimiter. |
|
DelimitedReader(Reader in,
char delimiter)
Constructs a new DelimitedReader. |
|
DelimitedReader(Reader in,
DelimitedParserConfiguration config)
Constructs a new DelimitedReader. |
Method Summary | |
---|---|
void |
close()
Closes this input stream. |
int |
getRecordLineNumber()
Returns the starting line number of the last record record. |
String |
getRecordText()
Returns the raw text of the last record read or null if the end of the stream was reached. |
String[] |
read()
Reads a single record from this input stream. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public DelimitedReader(Reader in)
in
- the input stream to read frompublic DelimitedReader(Reader in, char delimiter)
in
- the input stream to read fromdelimiter
- the field delimiting characterpublic DelimitedReader(Reader in, DelimitedParserConfiguration config)
in
- the input stream to read fromconfig
- the reader configuration settings or null to use default values
IllegalArgumentException
- if the delimiter matches the escape character or
or the line continuation characterMethod Detail |
---|
public int getRecordLineNumber()
getRecordLineNumber
in interface RecordReader
public String getRecordText()
getRecordText
in interface RecordReader
public String[] read() throws IOException
RecordReader
read
in interface RecordReader
IOException
- if an I/O error occurs reading from the streampublic void close() throws IOException
RecordReader
close
in interface RecordReader
IOException
- if an I/O error occurs closing the stream
|
BeanIO 2.0.4 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |