From: Manamohan Satapathy Date: Wed, 14 Mar 2018 08:01:38 +0000 (+0530) Subject: Policy:Blocker X-Git-Tag: v1.2.0~56^2 X-Git-Url: https://gerrit.onap.org/r/gitweb?p=policy%2Fengine.git;a=commitdiff_plain;h=d1aa00c101648ecfea24f01b379d3c1cfaff7b4c Policy:Blocker Use try-with-resources to close this JarFile:L590 L617 Issue-ID: POLICY-688 Sonar link:https://sonar.onap.org/issues?myIssues=true&open=AWF91iXI8TZzbCgU6anv&resolved=false&severities=BLOCKER Location:BRMSGateway\src\main\java\org\onap\policy\brmsInterface\BRMSPush.java Change-Id: I11f07325e78d6c7a9760496db4685546d2910595 Signed-off-by: Manamohan Satapathy --- diff --git a/BRMSGateway/src/main/java/org/onap/policy/brmsInterface/BRMSPush.java b/BRMSGateway/src/main/java/org/onap/policy/brmsInterface/BRMSPush.java index a1113f53d..86cd066b8 100644 --- a/BRMSGateway/src/main/java/org/onap/policy/brmsInterface/BRMSPush.java +++ b/BRMSGateway/src/main/java/org/onap/policy/brmsInterface/BRMSPush.java @@ -586,8 +586,8 @@ public class BRMSPush { } } - private void extractJar(String jarFileName, String artifactId) throws IOException { - JarFile jar = new JarFile(jarFileName); +private void extractJar(String jarFileName, String artifactId){ + try (JarFile jar = new JarFile(jarFileName)) { Enumeration enumEntries = jar.entries(); while (enumEntries.hasMoreElements()) { JarEntry file = (JarEntry) enumEntries.nextElement(); @@ -613,18 +613,20 @@ public class BRMSPush { f = new File(path + File.separator + fileName); } if (f != null) { - InputStream is = jar.getInputStream(file); - FileOutputStream fos = new FileOutputStream(f); + try (InputStream is = jar.getInputStream(file); FileOutputStream fos = new FileOutputStream(f)) { while (is.available() > 0) { fos.write(is.read()); } - fos.close(); - is.close(); LOGGER.info(fileName + " Created.."); + } catch (IOException e) { + LOGGER.info("exception Occured" + e); + } } - } - jar.close(); - } + } + } catch (IOException e) { + LOGGER.info("exception Occured" + e); + } + } private NexusArtifact getLatestArtifactFromNexus(String selectedName) { List artifacts = getArtifactFromNexus(selectedName, null);