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
ABeanReader
implementation.- 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 void
close()
Closes the underlying input stream.void
debug()
Prints the internal view of the stream configuration toSystem.out
void
debug(java.io.PrintStream out)
Prints the internal view of the stream configuration.int
getLineNumber()
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.RecordContext
getRecordContext(int index)
Returns record information for the most recent bean object read from this reader.int
getRecordCount()
Returns the number of records read from the underlying input stream for the most recent bean object read from this reader.java.lang.String
getRecordName()
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.Object
read()
Reads a single bean from the input stream.void
setErrorHandler(BeanReaderErrorHandler errorHandler)
Sets the error handler to handle exceptions thrown byBeanReader.read()
.void
setIgnoreUnidentifiedRecords(boolean ignoreUnidentifiedRecords)
Sets whether to ignore unidentified records.int
skip(int count)
Skips ahead in the input stream.
-
-
-
Constructor Detail
-
BeanReaderImpl
public BeanReaderImpl(UnmarshallingContext context, Selector layout)
Constructs a newBeanReaderImpl
.- Parameters:
context
- theUnmarshallingContext
layout
- the root component of the parser tree
-
-
Method Detail
-
read
public java.lang.Object read()
Description copied from interface:BeanReader
Reads a single bean from the input stream. If the end of the stream is reached, null is returned.- Specified by:
read
in 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, UnexpectedRecordException
Description copied from interface:BeanReader
Skips 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:
skip
in 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
count
if the end of the stream was reached - Throws:
BeanReaderIOException
- if the underlying input stream throws anIOException
or 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 BeanReaderIOException
Description copied from interface:BeanReader
Closes the underlying input stream.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfaceBeanReader
- Specified by:
close
in interfacejava.io.Closeable
- Throws:
BeanReaderIOException
- if the underlying input stream throws anIOException
or this reader was already closed
-
getRecordName
public java.lang.String getRecordName()
Description copied from interface:BeanReader
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.- Specified by:
getRecordName
in interfaceBeanReader
- Returns:
- the record or group name
-
getLineNumber
public int getLineNumber()
Description copied from interface:BeanReader
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. The line number may be zero if new lines are not used to separate characters.- Specified by:
getLineNumber
in interfaceBeanReader
- Returns:
- the line number
-
getRecordCount
public int getRecordCount()
Description copied from interface:BeanReader
Returns 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:
getRecordCount
in interfaceBeanReader
- Returns:
- the record count
-
getRecordContext
public RecordContext getRecordContext(int index)
Description copied from interface:BeanReader
Returns 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:
getRecordContext
in 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:BeanReader
Sets the error handler to handle exceptions thrown byBeanReader.read()
.- Specified by:
setErrorHandler
in 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:Debuggable
Prints the internal view of the stream configuration toSystem.out
- Specified by:
debug
in interfaceDebuggable
-
debug
public void debug(java.io.PrintStream out)
Description copied from interface:Debuggable
Prints the internal view of the stream configuration.- Specified by:
debug
in interfaceDebuggable
- Parameters:
out
- thePrintStream
to write to
-
-