Skip to content
Snippets Groups Projects
Commit 3a347692 authored by Christopher Bohn's avatar Christopher Bohn :thinking:
Browse files

Started refactor to using placeCSVonWriter instead of placeCSVonStream

This will give the client the responsibility for the lifecycle of the
injected dependency. This is good practice in its own right; however,
the elimination of the writer.close() method just seems appropriate
since all the client we're writing uses try-with-resources.
parent 00284940
No related branches found
No related tags found
No related merge requests found
...@@ -87,6 +87,11 @@ public class CSVReaderWriter { ...@@ -87,6 +87,11 @@ public class CSVReaderWriter {
static void placeCSVonStream(Collection<Map<String, String>> data, OutputStream outputStream) throws IOException { static void placeCSVonStream(Collection<Map<String, String>> data, OutputStream outputStream) throws IOException {
OutputStreamWriter writer = new OutputStreamWriter(outputStream); OutputStreamWriter writer = new OutputStreamWriter(outputStream);
placeCSVonWriter(data, writer);
writer.close();
}
static void placeCSVonWriter(Collection<Map<String, String>> data, OutputStreamWriter writer) {
CSVWriter csvWriter = new CSVWriter(writer); CSVWriter csvWriter = new CSVWriter(writer);
List<String[]> allLines = new LinkedList<>(); List<String[]> allLines = new LinkedList<>();
String[] fieldNames = getFieldNames(data); String[] fieldNames = getFieldNames(data);
...@@ -102,7 +107,6 @@ public class CSVReaderWriter { ...@@ -102,7 +107,6 @@ public class CSVReaderWriter {
allLines.add(values); allLines.add(values);
} }
csvWriter.writeAll(allLines, false); csvWriter.writeAll(allLines, false);
writer.close();
} }
private static String[] getFieldNames(Collection<Map<String, String>> data) { private static String[] getFieldNames(Collection<Map<String, String>> data) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment