From 65fcdf360a21e0b6fff35d6ccfa5afbe65902466 Mon Sep 17 00:00:00 2001 From: Kanagaraj Manickam k00365106 Date: Thu, 26 Apr 2018 15:49:02 +0530 Subject: Make use of try with resource Issue-ID: CLI-100 Change-Id: I96a0e3cf0e982c001adf6d6bf3c0a5ad8c23a110 Signed-off-by: Kanagaraj Manickam k00365106 --- .../org/onap/cli/fw/output/print/OnapCommandPrint.java | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) (limited to 'framework/src/main/java/org') 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> 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 - } } } -- cgit 1.2.3-korg