BeanIO 2.0.4

org.beanio.internal.parser
Class BeanReaderImpl

java.lang.Object
  extended by org.beanio.internal.parser.BeanReaderImpl
All Implemented Interfaces:
BeanReader

public class BeanReaderImpl
extends Object
implements BeanReader

A BeanReader implementation.

Since:
2.0
Author:
Kevin Seim

Constructor Summary
BeanReaderImpl(UnmarshallingContext context, Selector layout)
          Constructs a new BeanReaderImpl.
 
Method Summary
 void close()
          Closes the underlying input stream.
 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.
 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.
 Object read()
          Reads a single bean from the input stream.
 void setErrorHandler(BeanReaderErrorHandler errorHandler)
          Sets the error handler to handle exceptions thrown by BeanReader.read().
 void setIgnoreUnidentifiedRecords(boolean ignoreUnidentifiedRecords)
          Sets whether to ignore unidentified records.
 int skip(int count)
          Skips ahead in the input stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BeanReaderImpl

public BeanReaderImpl(UnmarshallingContext context,
                      Selector layout)
Constructs a new BeanReaderImpl.

Parameters:
context - the UnmarshallingContext
layout - the root component of the parser tree
Method Detail

read

public 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 interface BeanReader
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 interface BeanReader
Parameters:
count - the number of bean objects to skip over that would have been returned by calling BeanReader.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 an IOException or this reader was closed
MalformedRecordException - if the underlying input stream is malformed and a record could not be accurately skipped
UnidentifiedRecordException - if a record could not be identified
UnexpectedRecordException - 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 interface BeanReader
Throws:
BeanReaderIOException - if the underlying input stream throws an IOException or this reader was already closed

getRecordName

public 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 interface BeanReader
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 interface BeanReader
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 interface BeanReader
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 interface BeanReader
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 by BeanReader.read().

Specified by:
setErrorHandler in interface BeanReader
Parameters:
errorHandler - the BeanReaderErrorHandler

setIgnoreUnidentifiedRecords

public void setIgnoreUnidentifiedRecords(boolean ignoreUnidentifiedRecords)
Sets whether to ignore unidentified records. Defaults to false.

Parameters:
ignoreUnidentifiedRecords - true to ignore unidentified records, false otherwise

BeanIO 2.0.4

Copyright © 2010-2013 Kevin Seim