data-file-reader-csv
CSV File Format support.
This library adds CSV file format support to the DFR framework. If included in your project, the library will be automatically detected using Java’s ServiceLocator. In all cases, the CSV library assumes a consistent schema across all rows. Inconsistent schema will cause an exception. Furthermore, the CSV data decoder assumes that the first row of your CSV file consists of the column names. All data values will be read as strings.
<dependency> <groupId>net.krotscheck.dfr</groupId> <artifactId>data-file-reader-csv</artifactId> <version>1.0.10</version> </dependency>
Reading a CSV file
InputStream inputStream = ResourceUtil.getResourceAsStream("my_file.bson"); CSVDataDecoder decoder = new CSVDataDecoder(); decoder.setInputStream(inputStream); for(Map<String, Object> row : decoder) { // Do something } decoder.close();
Writing a CSV file
OutputStream outputStream = new FileOutputStream("my_file.bson"); IDataEncoder encoder = new CSVDataEncoder(outputStream); Map<String, Object> myRow = new LinkedHashMap<String, Object>(); encoder.write(myRow); encoder.close();