Skip to content
Diergo Easy CSV Streamable
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
gradle/wrapper
src
.gitignore
.travis.yml
CHANGELOG.md
CONTRIBUTING.md
LICENSE
README.md
build.gradle
gradle.properties
gradlew
gradlew.bat
settings.gradle

README.md

DeCS: Diergo Easy CSV Streamable

This Java library supports parsing and generation of comma separated value (csv) data as defined in RFC 4180.

The format is a simple line based text format for table data. Many databases or spreadsheet software like MS-Excel can use this data as an interchange format. Each line is a row of the table, the column values are separated by a comma (or an other character). If the separator or quote character is part of a column value, the value has to be quoted.

Usage

The diergo.csv package contains a tool box to read and write CSV data using Java 8 Streams and functional interfaces. You can easily connect the functionaliy by using map(), filter() and collect() of a Stream. As there are no direct dependencies of the tools you can simply extend it for your needs by creating new lambdas or functional interfaces and inject them to mappings and filters:

  List<Map<String, String>> lines = Readers.asLines(new FileReader("input.csv", StandardCharsets.UTF_8))
      // CSV parser turns each line into a row
      .map(CsvParserBuilder.csvParser().separatedBy(',').build()).flatMap(Collection::stream)
      // turn each line into a map, the first line is treated as header with column names
      .map(Maps.toMaps()).flatMap(Collection::stream);

  lines.stream()
      // create a stream of rows with an initial header row containing the column names
      .map(Maps.toRowsWithHeader()).flatMap(Collection::stream)
      // CSV printer turns each row into one line
      .map(CsvPrinterBuilder.csvPrinter().separatedBy(',').build())
      .collect(Appendables.toAppendable(new FileWriter("output.csv", StandardCharsets.UTF_8), '\n'));

There are more ready to use helper functions to filter and map at Rows, Maps and Values. Handling of comments, headers and separators is configured using the builders for CSV parser and printer. For the release notes, have a look at the change log.

Dependency Download

To integrate the library in your project, use the following dependency:

gradle:

  compile 'diergo:decs:3.1.1'

maven:

  <dependency>
    <groupId>diergo</groupId>
    <artifactId>decs</artifactId>
    <version>3.1.1</version>
  </dependency>

The library has no external dependencies except two optional ones:

License

This library is published under Apache License Version 2.0.

You can’t perform that action at this time.