CSVUtil

object CSVUtil

A class to facilitate some basic CSV processing without having to worry about underlying csv library. Helps with reading and writing arrays to csv files. Generally, exceptions are squashed.

Properties

Link copied to clipboard
val logger: KLogger

Functions

Link copied to clipboard
fun csvReader(pathToFile: Path): CSVParser?

Returns a CSVParser based on CSVFormat.DEFAULT. If there is a problem (e.g. IOException) null is returned.

Link copied to clipboard
fun readRows(pathToFile: Path, skipLines: Int = 0): List<CSVRecord>

Reads all rows from a csv file that may have the first row as a header of column labels and each subsequent row as the data for each column, e.g. "x", "y" 1.1, 2.0 4.3, 6.4 etc. This method squelches any IOExceptions. Writes warning to log. If there was a problem an empty list is returned.

Link copied to clipboard
fun readRowsToListOfStringArrays(pathToFile: Path, skipLines: Int = 0): List<Array<String>>

Reads all rows from a csv file that may have the first row as a header of column labels and each subsequent row as the data for each column, e.g. "x", "y" 1.1, 2.0 4.3, 6.4 etc. This method squelches any IOExceptions. Writes warning to log. If there was a problem an empty list is returned.

Link copied to clipboard

Reads data from a csv file that has the first row as a header of column labels and each subsequent row as the data for each column, e.g. "x", "y" 1.1, 2.0 4.3, 6.4 etc. The List names will hold ("x", "y"). If names has strings it will be cleared. The returned array will hold data0 = {1.1, 4.3} data1 = {2.0, 6.4} etc.

Link copied to clipboard
fun readToRows(names: MutableList<String>, pathToFile: Path): Array<DoubleArray>

Reads data from a csv file that has the first row as a header of column labels and each subsequent row as the data for each row, e.g. "x", "y" 1.1, 2.0 4.3, 6.4 etc. The List names will hold ("x", "y"). If names has strings it will be cleared. The returned array will hold data0 = {1.1, 2.0} data1 = {4.3, 6.4} etc.

Link copied to clipboard

For compatibility purposes converts the list of CSV records to a list of string arrays

Link copied to clipboard
fun writeArrayToCSVFile(array: Array<DoubleArray>, header: MutableList<String> = mutableListOf(), pathToFile: Path = KSL.outDir.resolve("arrayData.csv"))

IOException is squelched with a warning to the logger if there was a problem writing to the file.