summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--framework/src/main/java/org/onap/cli/fw/output/print/OnapCommandPrint.java18
1 files changed, 4 insertions, 14 deletions
diff --git a/framework/src/main/java/org/onap/cli/fw/output/print/OnapCommandPrint.java b/framework/src/main/java/org/onap/cli/fw/output/print/OnapCommandPrint.java
index 0c0c5a12..1f51ff38 100644
--- a/framework/src/main/java/org/onap/cli/fw/output/print/OnapCommandPrint.java
+++ b/framework/src/main/java/org/onap/cli/fw/output/print/OnapCommandPrint.java
@@ -220,11 +220,10 @@ public class OnapCommandPrint {
* exception
*/
public String printCsv() throws OnapCommandOutputPrintingFailed {
- StringWriter writer = new StringWriter();
- CSVPrinter printer = null;
- try {
- CSVFormat formattor = CSVFormat.DEFAULT.withRecordSeparator(System.getProperty("line.separator"));
- printer = new CSVPrinter(writer, formattor);
+ CSVFormat formattor = CSVFormat.DEFAULT.withRecordSeparator(System.getProperty("line.separator"));
+
+ try (StringWriter writer = new StringWriter();
+ CSVPrinter printer = new CSVPrinter(writer, formattor);) {
List<List<Object>> rows = this.formRows(false);
@@ -235,15 +234,6 @@ public class OnapCommandPrint {
return writer.toString();
} catch (IOException e) {
throw new OnapCommandOutputPrintingFailed(e);
- } finally {
- try {
- if (printer != null) {
- printer.close();
- }
- writer.close();
- } catch (IOException e) {
- throw new OnapCommandOutputPrintingFailed(e); // NOSONAR
- }
}
}