Package org.beanio.stream.fixedlength
Class FixedLengthReader
- java.lang.Object
-
- org.beanio.stream.fixedlength.FixedLengthReader
-
- All Implemented Interfaces:
RecordReader
public class FixedLengthReader extends java.lang.Object implements RecordReader
AFixedLengthReaderis used to read records from a fixed length file or input stream. A fixed length record is represented using theStringclass. 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.If a record may span multiple lines, a single line continuation character may be configured. The line continuation character must immediately precede the record termination character. Note that line continuation characters are not included in the record text.
- Since:
- 1.0
-
-
Constructor Summary
Constructors Constructor Description FixedLengthReader(java.io.Reader in)Constructs a newFixedLengthReader.FixedLengthReader(java.io.Reader in, FixedLengthParserConfiguration config)Constructs a newFixedLengthReader.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes this input stream.intgetRecordLineNumber()Returns the line number of the last record from this input stream.java.lang.StringgetRecordText()Returns the unparsed record text of the last record read.java.lang.Stringread()Reads a single record from this input stream.
-
-
-
Constructor Detail
-
FixedLengthReader
public FixedLengthReader(java.io.Reader in)
Constructs a newFixedLengthReader. By default, line continuation is disabled.- Parameters:
in- the input stream to read from
-
FixedLengthReader
public FixedLengthReader(java.io.Reader in, FixedLengthParserConfiguration config) throws java.lang.IllegalArgumentExceptionConstructs a newFixedLengthReader.- Parameters:
in- the input stream to read fromconfig- the reader configuration settings ornullto accept defaults- Throws:
java.lang.IllegalArgumentException- if a configuration setting is invalid- Since:
- 1.2
-
-
Method Detail
-
getRecordLineNumber
public int getRecordLineNumber()
Description copied from interface:RecordReaderReturns the line number of the last record from this input stream. If a record spans multiple lines, the line number at the beginning of the record is returned. May return -1 if the end of the stream was reached, or 0 if new lines are not used to terminate records.- Specified by:
getRecordLineNumberin interfaceRecordReader- Returns:
- the beginning line number of the last record read
-
getRecordText
public java.lang.String getRecordText()
Description copied from interface:RecordReaderReturns the unparsed record text of the last record read.- Specified by:
getRecordTextin interfaceRecordReader- Returns:
- the unparsed text of the last record read
-
read
public java.lang.String read() throws java.io.IOException, RecordIOExceptionDescription copied from interface:RecordReaderReads a single record from this input stream. The type of object returned depends on the format of the stream.- Specified by:
readin interfaceRecordReader- Returns:
- the record value, or null if the end of the stream was reached.
- Throws:
java.io.IOException- if an I/O error occurs reading from the streamRecordIOException- if the record is malformed and cannot be parsed, but subsequent reads may still be possible
-
close
public void close() throws java.io.IOExceptionDescription copied from interface:RecordReaderCloses this input stream.- Specified by:
closein interfaceRecordReader- Throws:
java.io.IOException- if an I/O error occurs closing the stream
-
-