Package org.beanio.internal.parser
Class BeanReaderImpl
- java.lang.Object
-
- org.beanio.internal.parser.BeanReaderImpl
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,BeanReader,Debuggable
public class BeanReaderImpl extends java.lang.Object implements BeanReader
ABeanReaderimplementation.- Since:
- 2.0
-
-
Constructor Summary
Constructors Constructor Description BeanReaderImpl(UnmarshallingContext context, Selector layout)Constructs a newBeanReaderImpl.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes the underlying input stream.voiddebug()Prints the internal view of the stream configuration toSystem.outvoiddebug(java.io.PrintStream out)Prints the internal view of the stream configuration.intgetLineNumber()Returns the starting line number of the first record for the most recent bean object read from this reader, or -1 when the end of the stream is reached.RecordContextgetRecordContext(int index)Returns record information for the most recent bean object read from this reader.intgetRecordCount()Returns the number of records read from the underlying input stream for the most recent bean object read from this reader.java.lang.StringgetRecordName()Returns the record or group name of the most recent bean object read from this reader, or null if the end of the stream was reached.java.lang.Objectread()Reads a single bean from the input stream.voidsetErrorHandler(BeanReaderErrorHandler errorHandler)Sets the error handler to handle exceptions thrown byBeanReader.read().voidsetIgnoreUnidentifiedRecords(boolean ignoreUnidentifiedRecords)Sets whether to ignore unidentified records.intskip(int count)Skips ahead in the input stream.
-
-
-
Constructor Detail
-
BeanReaderImpl
public BeanReaderImpl(UnmarshallingContext context, Selector layout)
Constructs a newBeanReaderImpl.- Parameters:
context- theUnmarshallingContextlayout- the root component of the parser tree
-
-
Method Detail
-
read
public java.lang.Object read()
Description copied from interface:BeanReaderReads a single bean from the input stream. If the end of the stream is reached, null is returned.- Specified by:
readin interfaceBeanReader- Returns:
- the Java bean read, or null if the end of the stream was reached
-
skip
public int skip(int count) throws BeanReaderIOException, MalformedRecordException, UnidentifiedRecordException, UnexpectedRecordExceptionDescription copied from interface:BeanReaderSkips ahead in the input stream. Record validation errors are ignored, but a malformed record, unidentified record, or record out of sequence, will cause an exception that halts stream reading. Exceptions thrown by this method are not passed to the error handler.- Specified by:
skipin interfaceBeanReader- Parameters:
count- the number of bean objects to skip over that would have been returned by callingBeanReader.read()- Returns:
- the number of skipped bean objects, which may be less than
countif the end of the stream was reached - Throws:
BeanReaderIOException- if the underlying input stream throws anIOExceptionor this reader was closedMalformedRecordException- if the underlying input stream is malformed and a record could not be accurately skippedUnidentifiedRecordException- if a record could not be identifiedUnexpectedRecordException- if a record is out of sequence
-
close
public void close() throws BeanReaderIOExceptionDescription copied from interface:BeanReaderCloses the underlying input stream.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfaceBeanReader- Specified by:
closein interfacejava.io.Closeable- Throws:
BeanReaderIOException- if the underlying input stream throws anIOExceptionor this reader was already closed
-
getRecordName
public java.lang.String getRecordName()
Description copied from interface:BeanReaderReturns the record or group name of the most recent bean object read from this reader, or null if the end of the stream was reached.- Specified by:
getRecordNamein interfaceBeanReader- Returns:
- the record or group name
-
getLineNumber
public int getLineNumber()
Description copied from interface:BeanReaderReturns the starting line number of the first record for the most recent bean object read from this reader, or -1 when the end of the stream is reached. The line number may be zero if new lines are not used to separate characters.- Specified by:
getLineNumberin interfaceBeanReader- Returns:
- the line number
-
getRecordCount
public int getRecordCount()
Description copied from interface:BeanReaderReturns the number of records read from the underlying input stream for the most recent bean object read from this reader. This typically returns 1 unless a bean object was mapped to a record group which may span multiple records.- Specified by:
getRecordCountin interfaceBeanReader- Returns:
- the record count
-
getRecordContext
public RecordContext getRecordContext(int index)
Description copied from interface:BeanReaderReturns record information for the most recent bean object read from this reader. If a bean object can span multiple records,BeanReader.getRecordCount()can be used to determine how many records were read from the stream.- Specified by:
getRecordContextin interfaceBeanReader- Parameters:
index- the index of the record, starting at 0- Returns:
- the
RecordContext - See Also:
BeanReader.getRecordCount()
-
setErrorHandler
public void setErrorHandler(BeanReaderErrorHandler errorHandler)
Description copied from interface:BeanReaderSets the error handler to handle exceptions thrown byBeanReader.read().- Specified by:
setErrorHandlerin interfaceBeanReader- Parameters:
errorHandler- theBeanReaderErrorHandler
-
setIgnoreUnidentifiedRecords
public void setIgnoreUnidentifiedRecords(boolean ignoreUnidentifiedRecords)
Sets whether to ignore unidentified records. Defaults to false.- Parameters:
ignoreUnidentifiedRecords- true to ignore unidentified records, false otherwise
-
debug
public void debug()
Description copied from interface:DebuggablePrints the internal view of the stream configuration toSystem.out- Specified by:
debugin interfaceDebuggable
-
debug
public void debug(java.io.PrintStream out)
Description copied from interface:DebuggablePrints the internal view of the stream configuration.- Specified by:
debugin interfaceDebuggable- Parameters:
out- thePrintStreamto write to
-
-