diff options
author | ramverma <ram.krishna.verma@ericsson.com> | 2018-09-17 15:55:06 +0100 |
---|---|---|
committer | ramverma <ram.krishna.verma@ericsson.com> | 2018-09-17 17:23:33 +0100 |
commit | 7c0424863e18773e4504af6f2f04416ec314e7a7 (patch) | |
tree | 4152e58e6df1f26e00e39ca3a882ca9697efac33 /plugins/reception-plugins | |
parent | 56f01f55d862df459ee37ad63a152ab3776a9337 (diff) |
Fix sonar bug in distribution
Change-Id: I6bcb6f6af1020ceb22dd92d6633717d2a183d5b8
Issue-ID: POLICY-1035
Signed-off-by: ramverma <ram.krishna.verma@ericsson.com>
Diffstat (limited to 'plugins/reception-plugins')
-rw-r--r-- | plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicy.java | 39 |
1 files changed, 9 insertions, 30 deletions
diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicy.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicy.java index 80c5172f..06a57a39 100644 --- a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicy.java +++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicy.java @@ -70,46 +70,25 @@ public class PolicyDecoderFileInCsarToPolicy implements PolicyDecoder<Csar, Poli @Override public Collection<PolicyAsString> decode(final Csar csar) throws PolicyDecodingException { final Collection<PolicyAsString> policyList = new ArrayList<>(); - ZipFile zipFile = null; - try { - zipFile = new ZipFile(csar.getCsarPath()); + + try (ZipFile zipFile = new ZipFile(csar.getCsarPath())) { final Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) { final ZipEntry entry = entries.nextElement(); if (entry.getName().contains(decoderParameters.getPolicyFileName())) { - final PolicyAsString poilcy = createPolicy(zipFile, entry); - policyList.add(poilcy); + final StringWriter writer = new StringWriter(); + IOUtils.copy(zipFile.getInputStream(entry), writer, "UTF-8"); + final PolicyAsString policy = new PolicyAsString(decoderParameters.getPolicyFileName(), + decoderParameters.getPolicyType(), writer.toString()); + policyList.add(policy); } } - } catch (final IOException exp) { + } catch (final IOException exp) { // NOSONAR final String message = "Failed decoding the policy"; LOGGER.error(message, exp); throw new PolicyDecodingException(message, exp); - } finally { - if (zipFile != null) { - try { - zipFile.close(); - } catch (final IOException exp) { - LOGGER.error("Failed closing the zipFile", exp); - } - } } - return policyList; - } - /** - * Creates the policy from given input. - * - * @param zipFile the csar file - * @param entry an entry in the csar file - * @return the created policy - * @throws IOException if policy creation fails - */ - private PolicyAsString createPolicy(final ZipFile zipFile, final ZipEntry entry) throws IOException { - final StringWriter writer = new StringWriter(); - IOUtils.copy(zipFile.getInputStream(entry), writer, "UTF-8"); - final PolicyAsString poilcy = new PolicyAsString(decoderParameters.getPolicyFileName(), - decoderParameters.getPolicyType(), writer.toString()); - return poilcy; + return policyList; } } |