Lazy CSV reader: plain java, no dependencies, streaming, resource reader, unzip, autodetect delimiters, Immutable, InnerCSV NullPointerException or IndexOutOfBoundsException
ClassName | UsageType | Description |
---|---|---|
StreamCSV | static | Stream methods (lazy) |
ConsumeCSV | static | Consumer methods (lazy) |
ListCsv | static | List methods (in memory) |
CsvReader | Object | Configurable reader |
Options | Type | Default | Description |
---|---|---|---|
Skip | long | -1 | Lines to skip while reading csv |
charset | Charset | UTF_8 | Charset to use for decoding the CSV file |
unzip | boolean | false | On true detects and extracts the CSV file automatically |
autoSep | boolean | false | On true detects the separator automatically |
separators | char... | ',' | Splits the CSV rows at the given separator |
final List<CsvRow> csvList = ListCsv.listCsv(EXAMPLE_CSV);
ConsumeCSV.consumeCsv(EXAMPLE_CSV,System.out::println);
try(final Stream<CsvRow> csvStream = StreamCSV.streamCSV(EXAMPLE_CSV)){
csvStream.forEach(System.out::println);
}
import static berlin.yuna.logic.CsvReader.csvReader;
public class CsvReaderTest {
//configuration
CsvReader reader = csvReader().skipLines(1).charset(UTF_8).separator(';').unzip(true).autoSep(true);
//read
List<CsvRow> allLines = reader.readAllRows(EXAMPLE_CSV);
//consume
reader.consume(EXAMPLE_CSV,System.out::println);
//stream
try(final Stream<CsvRow> lazyStream = reader.streamCSV(EXAMPLE_CSV)){
lazyStream.forEach(System.out::println);
}
}
final List<CsvRow> csvRows = ListCSV.listCSV(EXAMPLE_CSV)
final CsvRow firstColumn = csvRows.get(0);
final CsvRow innerCSV = firstColumn.get(0, ',');