Package csv.util

Class ObjectReader<T>

java.lang.Object
csv.util.ObjectReader<T>
All Implemented Interfaces:
Iterable<T>, Iterator<T>

public class ObjectReader<T> extends Object implements Iterator<T>, Iterable<T>
Reads objects from a table.

This class is different to BeanReader as it asks a converter to convert the row.

 // Create an instance of your table reader 
 TableReader tableReader = ...; 
 
 // Get an instance of your row converter
 RowConverter<MyClass> converter = new MyClassConverter();
 
 // Now read from the table stream
 ObjectReader<MyClass> reader = new ObjectReader(tableReader, converter, true);
 Object tableHeader[] = reader.getTableHeader();
 while (reader.hasNext()) {
    MyClass myObject = reader.next();
    
    // do something...
 }
 
 // Close the reader
 reader.close();
 
Author:
ralph
  • Field Details

  • Constructor Details

    • ObjectReader

      public ObjectReader(TableReader reader, RowConverter<T> converter, boolean hasHeaderRow)
      Constructor.
      Parameters:
      reader - the underlying table reader
      converter - the converter to be used
      hasHeaderRow - whether the table has a table header to read
  • Method Details

    • getTableHeader

      public Object[] getTableHeader()
      Returns the header row that was read.
      Returns:
      the header row or null if no such row was read.
    • getConverter

      public RowConverter<T> getConverter()
      Returns the row converter.
      Returns:
      the row converter
    • setConverter

      public void setConverter(RowConverter<T> converter)
      Sets the row converter.
      Parameters:
      converter - the row converter to be used
    • iterator

      public Iterator<T> iterator()
      Specified by:
      iterator in interface Iterable<T>
    • hasNext

      public boolean hasNext()
      Specified by:
      hasNext in interface Iterator<T>
    • next

      public T next()
      Specified by:
      next in interface Iterator<T>
    • close

      public void close()
      Closes the stream.