aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicy.java39
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;
}
}