From 3a3476922cdac0538ff58e6549608ea3a9a8fea5 Mon Sep 17 00:00:00 2001
From: Christopher Bohn <bohn@unl.edu>
Date: Sun, 19 Jan 2020 08:30:36 -0600
Subject: [PATCH] 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.
---
 src/main/java/edu/unl/cse/csv_io/CSVReaderWriter.java | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/main/java/edu/unl/cse/csv_io/CSVReaderWriter.java b/src/main/java/edu/unl/cse/csv_io/CSVReaderWriter.java
index 4f42ddf..f81437c 100644
--- a/src/main/java/edu/unl/cse/csv_io/CSVReaderWriter.java
+++ b/src/main/java/edu/unl/cse/csv_io/CSVReaderWriter.java
@@ -87,6 +87,11 @@ public class CSVReaderWriter {
 
     static void placeCSVonStream(Collection<Map<String, String>> data, OutputStream outputStream) throws IOException {
         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);
         List<String[]> allLines = new LinkedList<>();
         String[] fieldNames = getFieldNames(data);
@@ -102,7 +107,6 @@ public class CSVReaderWriter {
             allLines.add(values);
         }
         csvWriter.writeAll(allLines, false);
-        writer.close();
     }
 
     private static String[] getFieldNames(Collection<Map<String, String>> data) {
-- 
GitLab