From 8571469c9de499b29b2b66b0b4a1bf94ca6190d6 Mon Sep 17 00:00:00 2001 From: Oliver Siegmar Date: Tue, 22 Aug 2023 18:46:41 +0200 Subject: [PATCH 1/2] fix example --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 68a65d5a..42a9315e 100644 --- a/README.md +++ b/README.md @@ -104,7 +104,7 @@ Iterative reading of some CSV data with a header ```java NamedCsvReader.builder().build("header 1,header 2\nfield 1,field 2") - .forEach(csvRecord -> csvRecord.getField("header 2")); + .forEach(csvRecord -> System.out.println(csvRecord.getField("header 2"))); ``` For more examples see [NamedCsvReaderExample.java](src/example/java/example/NamedCsvReaderExample.java) From cce57e305f8515e9d9ea208c9c2ec359991c76ae Mon Sep 17 00:00:00 2001 From: Oliver Siegmar Date: Tue, 22 Aug 2023 19:09:26 +0200 Subject: [PATCH 2/2] updated the Upgrade doc --- README.md | 5 ++--- UPGRADING.md | 50 +++++++++++++++++++++++++++++--------------------- 2 files changed, 31 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 42a9315e..f651bcf9 100644 --- a/README.md +++ b/README.md @@ -159,10 +159,9 @@ CsvWriter.builder() For more examples see [CsvWriterExample.java](src/example/java/example/CsvWriterExample.java). -## Upgrading from version 1.x +## Upgrading from an older version -Please see [UPGRADING.md](UPGRADING.md) for an overview of the main functionality of 1.x -and how to upgrade them to version 2. +Please see [UPGRADING.md](UPGRADING.md) for a list of breaking changes in version 3 and how to upgrade. --- diff --git a/UPGRADING.md b/UPGRADING.md index 0f1341ff..73f537ca 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -1,7 +1,12 @@ -# Migrating from 1.0.x to 2.x +# Upgrading to 3.0 -This document shows the most commonly used features of FastCSV 1.x -and how these can be migrated to version 2 easily. +This document shows a list of breaking changes in version 3 and how to upgrade. + +- Java version requirement raised from version 8 to 11 +- This also raised the required Android API level from version 26 (Android 8) to 33 (Android 13) +- Rows are now called Records (aligned to RFC 4180) + +If you're still on version 1, read on. ## Reader @@ -21,7 +26,7 @@ New way: CsvReader.builder() .fieldSeparator(',') .quoteCharacter('"') - .skipEmptyRows(true) + .skipEmptyRecords(true) .errorOnDifferentFieldCount(false); ``` @@ -40,8 +45,8 @@ try (CsvParser csvParser = new CsvReader().parse(file, UTF_8)) { New way: ```java try (CsvReader csvReader = CsvReader.builder().build(path)) { - csvReader.forEach(row -> - System.out.println("First column of line: " + row.getField(0)) + csvReader.forEach(csvRecord -> + System.out.println("First column of line: " + csvRecord.getField(0)) ); } ``` @@ -63,8 +68,8 @@ try (CsvParser csvParser = csvReader.parse(file, UTF_8)) { New way: ```java try (NamedCsvReader csvReader = NamedCsvReader.builder().build(path)) { - csvReader.forEach(row -> - System.out.println("Column named firstname: " + row.getField("firstname")) + csvReader.forEach(csvRecord -> + System.out.println("Column named firstname: " + csvRecord.getField("firstname")) ); } ``` @@ -80,9 +85,12 @@ New way: The container concept has been removed, but you can easily build something similar using the Java Stream API. ```java -List data; -try (CsvReader csvReader = CsvReader.builder().build(path)) { - data = csvReader.stream().collect(Collectors.toList()); +List data; +try (CsvReader csv = CsvReader.builder().build(path)) { + data = csv.stream().toList(); + + // or in Java < 16: + // data = csv.stream().collect(Collectors.toList()); } ``` @@ -110,7 +118,7 @@ CsvWriter.builder() > :warning: Also note that the default line delimiter has changed! > In version 1.x the line delimiter was set based on system default `System.lineSeparator()`. -> In version 2.x the default is `\r\n` as defined in RFC 4180. +> In version 2/3 the default is `\r\n` as defined in RFC 4180. ### Write to file @@ -124,10 +132,10 @@ try (CsvAppender csvAppender = new CsvWriter().append(file)) { New way: ```java -try (CsvWriter csvWriter = CsvWriter.builder().build(file)) { - csvWriter - .writeRow("header1", "header2") - .writeRow("value1", "value2"); +try (CsvWriter csv = CsvWriter.builder().build(file)) { + csv + .writeRecord("header1", "header2") + .writeRecord("value1", "value2"); } ``` @@ -145,14 +153,14 @@ try (CsvAppender csvAppender = new CsvWriter().append(writer)) { New way: ```java Writer writer = new StringWriter(); -try (CsvWriter csvWriter = CsvWriter.builder().build(writer)) { - csvWriter - .writeRow("header1", "header2") - .writeRow("value1", "value2"); +try (CsvWriter csv = CsvWriter.builder().build(writer)) { + csv + .writeRecord("header1", "header2") + .writeRecord("value1", "value2"); } ``` > :warning: Be aware of a change in the semantic in FastCSV. -> In version 2.x you probably want to pass in a `java.io.BufferedWriter` for proper +> In version 2/3 you probably want to pass in a `java.io.BufferedWriter` for proper > performance. The opposite was recommended in version 1.x. > Check the Javadoc for further information.