From a1997873f5f0dce0f219182021e0f04c7e8a6ece Mon Sep 17 00:00:00 2001 From: agathe keromnes Date: Thu, 23 Aug 2018 11:35:35 +0200 Subject: [PATCH 1/3] add the possibility to disable all quotes in a csv file --- .../windmill/exports/exporters/csv/CsvExporter.java | 13 ++++++------- .../exports/exporters/csv/ExportCsvConfig.java | 3 +++ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/coreoz/windmill/exports/exporters/csv/CsvExporter.java b/src/main/java/com/coreoz/windmill/exports/exporters/csv/CsvExporter.java index aff964b..59d87ec 100644 --- a/src/main/java/com/coreoz/windmill/exports/exporters/csv/CsvExporter.java +++ b/src/main/java/com/coreoz/windmill/exports/exporters/csv/CsvExporter.java @@ -1,16 +1,15 @@ package com.coreoz.windmill.exports.exporters.csv; +import com.coreoz.windmill.exports.config.ExportMapping; +import com.opencsv.CSVWriter; +import lombok.SneakyThrows; + import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.util.List; -import com.coreoz.windmill.exports.config.ExportMapping; -import com.opencsv.CSVWriter; - -import lombok.SneakyThrows; - public class CsvExporter { private final Iterable rows; @@ -71,7 +70,7 @@ private void writeHeaderRow() { for (int i = 0; i < headerColumn.size(); i++) { csvRowValues[i] = stringValue(headerColumn.get(i)); } - csvWriter.writeNext(csvRowValues); + csvWriter.writeNext(csvRowValues,!exportConfig.isDisabledQuotes()); } } @@ -81,7 +80,7 @@ private void writeRow(T row) { for (int i = 0; i < mapping.columnsCount(); i++) { csvRowValues[i] = stringValue(mapping.cellValue(i, row)); } - csvWriter.writeNext(csvRowValues); + csvWriter.writeNext(csvRowValues, !exportConfig.isDisabledQuotes()); csvWriter.flush(); } diff --git a/src/main/java/com/coreoz/windmill/exports/exporters/csv/ExportCsvConfig.java b/src/main/java/com/coreoz/windmill/exports/exporters/csv/ExportCsvConfig.java index ff78361..ccd4ba9 100644 --- a/src/main/java/com/coreoz/windmill/exports/exporters/csv/ExportCsvConfig.java +++ b/src/main/java/com/coreoz/windmill/exports/exporters/csv/ExportCsvConfig.java @@ -23,5 +23,8 @@ public class ExportCsvConfig { @Builder.Default private final char escapeChar = ICSVParser.DEFAULT_ESCAPE_CHARACTER; /** The line feed terminator to use */ @Builder.Default private final String lineEnd = CSVWriter.DEFAULT_LINE_END; + /** boolean to disable quotes*/ + @Builder.Default private final boolean disabledQuotes = ICSVParser.DEFAULT_STRICT_QUOTES; + } From 8c8415933e38e0a0879072864aed8ea242b11c16 Mon Sep 17 00:00:00 2001 From: agathe keromnes Date: Wed, 12 Sep 2018 09:34:49 +0200 Subject: [PATCH 2/3] rename disabledQuotes to applyQuotesToAll --- .../windmill/exports/exporters/csv/CsvExporter.java | 13 +++++++------ .../exports/exporters/csv/ExportCsvConfig.java | 4 ++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/coreoz/windmill/exports/exporters/csv/CsvExporter.java b/src/main/java/com/coreoz/windmill/exports/exporters/csv/CsvExporter.java index 59d87ec..fbb45b1 100644 --- a/src/main/java/com/coreoz/windmill/exports/exporters/csv/CsvExporter.java +++ b/src/main/java/com/coreoz/windmill/exports/exporters/csv/CsvExporter.java @@ -1,15 +1,16 @@ package com.coreoz.windmill.exports.exporters.csv; -import com.coreoz.windmill.exports.config.ExportMapping; -import com.opencsv.CSVWriter; -import lombok.SneakyThrows; - import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.util.List; +import com.coreoz.windmill.exports.config.ExportMapping; +import com.opencsv.CSVWriter; + +import lombok.SneakyThrows; + public class CsvExporter { private final Iterable rows; @@ -70,7 +71,7 @@ private void writeHeaderRow() { for (int i = 0; i < headerColumn.size(); i++) { csvRowValues[i] = stringValue(headerColumn.get(i)); } - csvWriter.writeNext(csvRowValues,!exportConfig.isDisabledQuotes()); + csvWriter.writeNext(csvRowValues,!exportConfig.isApplyQuotesToAll()); } } @@ -80,7 +81,7 @@ private void writeRow(T row) { for (int i = 0; i < mapping.columnsCount(); i++) { csvRowValues[i] = stringValue(mapping.cellValue(i, row)); } - csvWriter.writeNext(csvRowValues, !exportConfig.isDisabledQuotes()); + csvWriter.writeNext(csvRowValues, !exportConfig.isApplyQuotesToAll()); csvWriter.flush(); } diff --git a/src/main/java/com/coreoz/windmill/exports/exporters/csv/ExportCsvConfig.java b/src/main/java/com/coreoz/windmill/exports/exporters/csv/ExportCsvConfig.java index ccd4ba9..3a068c9 100644 --- a/src/main/java/com/coreoz/windmill/exports/exporters/csv/ExportCsvConfig.java +++ b/src/main/java/com/coreoz/windmill/exports/exporters/csv/ExportCsvConfig.java @@ -23,8 +23,8 @@ public class ExportCsvConfig { @Builder.Default private final char escapeChar = ICSVParser.DEFAULT_ESCAPE_CHARACTER; /** The line feed terminator to use */ @Builder.Default private final String lineEnd = CSVWriter.DEFAULT_LINE_END; - /** boolean to disable quotes*/ - @Builder.Default private final boolean disabledQuotes = ICSVParser.DEFAULT_STRICT_QUOTES; + /** The boolean to use for applying or not optional wrapping quotes */ + @Builder.Default private final boolean applyQuotesToAll = ICSVParser.DEFAULT_STRICT_QUOTES; } From d12a35557df8940fe1f106154f49241452d9757b Mon Sep 17 00:00:00 2001 From: agathe keromnes Date: Wed, 12 Sep 2018 10:46:02 +0200 Subject: [PATCH 3/3] change !isApplyQuotesToAll --- .../coreoz/windmill/exports/exporters/csv/CsvExporter.java | 4 ++-- .../windmill/exports/exporters/csv/ExportCsvConfig.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/coreoz/windmill/exports/exporters/csv/CsvExporter.java b/src/main/java/com/coreoz/windmill/exports/exporters/csv/CsvExporter.java index fbb45b1..f34c219 100644 --- a/src/main/java/com/coreoz/windmill/exports/exporters/csv/CsvExporter.java +++ b/src/main/java/com/coreoz/windmill/exports/exporters/csv/CsvExporter.java @@ -71,7 +71,7 @@ private void writeHeaderRow() { for (int i = 0; i < headerColumn.size(); i++) { csvRowValues[i] = stringValue(headerColumn.get(i)); } - csvWriter.writeNext(csvRowValues,!exportConfig.isApplyQuotesToAll()); + csvWriter.writeNext(csvRowValues,exportConfig.isApplyQuotesToAll()); } } @@ -81,7 +81,7 @@ private void writeRow(T row) { for (int i = 0; i < mapping.columnsCount(); i++) { csvRowValues[i] = stringValue(mapping.cellValue(i, row)); } - csvWriter.writeNext(csvRowValues, !exportConfig.isApplyQuotesToAll()); + csvWriter.writeNext(csvRowValues, exportConfig.isApplyQuotesToAll()); csvWriter.flush(); } diff --git a/src/main/java/com/coreoz/windmill/exports/exporters/csv/ExportCsvConfig.java b/src/main/java/com/coreoz/windmill/exports/exporters/csv/ExportCsvConfig.java index 3a068c9..940efac 100644 --- a/src/main/java/com/coreoz/windmill/exports/exporters/csv/ExportCsvConfig.java +++ b/src/main/java/com/coreoz/windmill/exports/exporters/csv/ExportCsvConfig.java @@ -24,7 +24,7 @@ public class ExportCsvConfig { /** The line feed terminator to use */ @Builder.Default private final String lineEnd = CSVWriter.DEFAULT_LINE_END; /** The boolean to use for applying or not optional wrapping quotes */ - @Builder.Default private final boolean applyQuotesToAll = ICSVParser.DEFAULT_STRICT_QUOTES; + @Builder.Default private final boolean applyQuotesToAll = true; }