Package org.beanio

Interface BeanReader

  • All Superinterfaces:
    java.lang.AutoCloseable, java.io.Closeable, Debuggable
    All Known Implementing Classes:
    BeanReaderImpl

    public interface BeanReader
    extends Debuggable, java.io.Closeable
    Interface for unmarshalling bean objects from an input stream.

    A BeanReader is created using a StreamFactory and a mapping file.

    Since:
    1.0
    See Also:
    StreamFactory
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      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.
      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 by read().
      int skip​(int count)
      Skips ahead in the input stream.
    • Method Detail

      • getRecordName

        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.
        Returns:
        the record or group name
      • getLineNumber

        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. The line number may be zero if new lines are not used to separate characters.
        Returns:
        the line number
      • getRecordCount

        int getRecordCount()
        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.
        Returns:
        the record count
        Since:
        2.0
      • getRecordContext

        RecordContext getRecordContext​(int index)
                                throws java.lang.IndexOutOfBoundsException
        Returns record information for the most recent bean object read from this reader. If a bean object can span multiple records, getRecordCount() can be used to determine how many records were read from the stream.
        Parameters:
        index - the index of the record, starting at 0
        Returns:
        the RecordContext
        Throws:
        java.lang.IndexOutOfBoundsException - if there is no record for the given index
        Since:
        2.0
        See Also:
        getRecordCount()
      • close

        void close()
            throws BeanReaderIOException
        Closes the underlying input stream.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        BeanReaderIOException - if the underlying input stream throws an IOException or this reader was already closed