This class is part of the lower level API for processing CSV data.
This class is part of the lower level API for processing CSV data. This is a CSV parser that produces the data through the scala.collection.Iterator trait. The data is read into a sequence of StringCell instances. StringCells can be written back to disk with CsvWriter.
This class does parsing in streaming fashion ie. you should be able to
handle files larger than what can fit in RAM, though this has
not been tested yet. The actual parsing is delegated to CsvReaderInternal.
This class just implements the Scala Iterator
interface on top of CsvReaderInternal.
If an error is encountered in the input a CsvReaderError will be returned
as the Left
of Either
. After this the iterator is exhausted and hasNext
will return
false. Note that the input stream will be left open in this situation.
If next
is called when hasNext
is false
, a NoSuchElementException
will
be thrown as usual. See the method throwOnError for a shortcut to enable
exception based error handling.
This example code will pick the second column from the csvData
and print the toString
of each Cell
from that column. Note the use of throwOnError
to bypass the Either
normally returned by the reader.
import fi.pelam.csv.cell._ import fi.pelam.csv.stream._ val csvData = "apple,0.99,3\n" + "orange,1.25,2\n" + "banana,0.80,4\n" val pickedCol = ColKey(1) for (cell <- new CsvReader(csvData).throwOnError; if cell.colKey == pickedCol) { println(cell) } // Running the code above will print the cells from the second column: Cell containing '0.99' at Row 1, Column B (1) Cell containing '1.25' at Row 2, Column B (1) Cell containing '0.80' at Row 3, Column B (1)
A note on closing the input stream. The
java.io.Reader is closed only if the
CSV data exhausted. In the case of an error and in the case of stopping to call the read
method before the input ends it is the responsibility of the caller to close the stream.
CsvReader produces these in various situations when it can't understand the input CSV data.
CsvReader produces these in various situations when it can't understand the input CSV data.
is a descriptive message.
last known coordinates in CSV data (or corresponding spreadsheet).
State machine based CSV parser which has single method interface which returns an option of eiher cell or error.
State machine based CSV parser which has single method interface which returns an option of eiher cell or error.
See CsvReader for friendlier Scala like interface (specifically Iterator).
Opposite of CsvReader.
Opposite of CsvReader. The API is simple. There are just 3 public methods. One to write a single cell and another to write a TraversableOnce of cells.
The third method goToNextRow
should be called last after the last cell to write the line
feed at the end of the file.
The cells are expected to be in top to bottom left to right order. The sequence of cells can contain holes. Empty cells in CSV data will be emitted for those.
This class handles quoting, but all other special processing is handled by fi.pelam.csv.cell.Cell.serializedString implementations.
This class does not flush or close the output stream. Client must take care of that.
This package contains the streaming oriented API for processing CSV data.
See the reader and writer classes for more information.
CsvWriter
CsvReader