Package csv.util
Class ObjectReader<T>
java.lang.Object
csv.util.ObjectReader<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 Summary
FieldsModifier and TypeFieldDescriptionprotected RowConverter<T>protected TableReaderprotected Object[] -
Constructor Summary
ConstructorsConstructorDescriptionObjectReader(TableReader reader, RowConverter<T> converter, boolean hasHeaderRow) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the stream.Returns the row converter.Object[]Returns the header row that was read.booleanhasNext()iterator()next()voidsetConverter(RowConverter<T> converter) Sets the row converter.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliteratorMethods inherited from interface java.util.Iterator
forEachRemaining, remove
-
Field Details
-
reader
-
iterator
-
converter
-
tableHeader
-
-
Constructor Details
-
ObjectReader
Constructor.- Parameters:
reader- the underlying table readerconverter- the converter to be usedhasHeaderRow- whether the table has a table header to read
-
-
Method Details
-
getTableHeader
Returns the header row that was read.- Returns:
- the header row or null if no such row was read.
-
getConverter
Returns the row converter.- Returns:
- the row converter
-
setConverter
Sets the row converter.- Parameters:
converter- the row converter to be used
-
iterator
-
hasNext
public boolean hasNext() -
next
-
close
public void close()Closes the stream.
-