Package com.gengoai.io
Class CSVReader
- java.lang.Object
-
- com.gengoai.io.CSVReader
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
void
forEach(Consumer<? super List<String>> consumer)
Convenience method for consuming all rows in the CSV fileList<String>
getHeader()
Gets the header read in from the csv file or specified via the CSV specification.Iterator<List<String>>
iterator()
List<String>
nextRow()
Reads the next row from the CSV file retuning null if there are not anymore<R> List<R>
processRows(SerializableFunction<List<String>,Optional<R>> converter)
List<List<String>>
readAll()
Runs the iterator over the entire resource returning all the rows it processed.Stream<List<String>>
stream()
Creates a new stream over the rows in the file that will close underlying reader on stream close.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
spliterator
-
-
-
-
Constructor Detail
-
CSVReader
public CSVReader(CSV builder, Reader reader) throws IOException
Instantiates a new CSVReader.- Parameters:
builder
- the CSV specificationreader
- the reader to read from- Throws:
IOException
- Something went wrong initializing the CSVReader
-
-
Method Detail
-
close
public void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
forEach
public void forEach(Consumer<? super List<String>> consumer)
Convenience method for consuming all rows in the CSV file
-
getHeader
public List<String> getHeader()
Gets the header read in from the csv file or specified via the CSV specification.- Returns:
- The header of the CSV file
-
nextRow
public List<String> nextRow() throws IOException
Reads the next row from the CSV file retuning null if there are not anymore- Returns:
- the row as a list of strings or null if there are not any more rows to read
- Throws:
IOException
- Something went wrong reading the file
-
processRows
public <R> List<R> processRows(SerializableFunction<List<String>,Optional<R>> converter) throws IOException
- Throws:
IOException
-
readAll
public List<List<String>> readAll() throws IOException
Runs the iterator over the entire resource returning all the rows it processed.- Returns:
- the list of rows (lists)
- Throws:
IOException
- the iO exception
-
-