diff options
author | Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com> | 2018-04-26 15:49:02 +0530 |
---|---|---|
committer | Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com> | 2018-04-26 15:49:02 +0530 |
commit | 65fcdf360a21e0b6fff35d6ccfa5afbe65902466 (patch) | |
tree | 15b24764d23a9405aaf6fb9c04a43b0d52e05e48 | |
parent | 1e8667ea274561d50b8669d88cc5c4564ed82bc6 (diff) |
Make use of try with resource
Issue-ID: CLI-100
Change-Id: I96a0e3cf0e982c001adf6d6bf3c0a5ad8c23a110
Signed-off-by: Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
-rw-r--r-- | framework/src/main/java/org/onap/cli/fw/output/print/OnapCommandPrint.java | 18 |
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 - } } } |