ZipOutputStream Cleanup 37/27637/4
authorya107f <ya107f@intl.att.com>
Mon, 8 Jan 2018 12:04:44 +0000 (14:04 +0200)
committerVitaly Emporopulo <Vitaliy.Emporopulo@amdocs.com>
Wed, 10 Jan 2018 15:04:28 +0000 (15:04 +0000)
Enclose ZipOutputStream handling with try with resources block for
proper stream cleanup.

Change-Id: I2565ef411519f127208a4f966001edf735cb68c0
Signed-off-by: ya107f <ya107f@intl.att.com>
Issue-ID: SDC-886
Signed-off-by: vempo <vitaliy.emporopulo@amdocs.com>
common-app-api/src/main/java/org/openecomp/sdc/common/util/ZipUtil.java

index 386a66b..c9207b2 100644 (file)
@@ -128,13 +128,14 @@ public class ZipUtil {
 
        public static byte[] zipBytes(byte[] input) throws IOException {
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
-               ZipOutputStream zos = new ZipOutputStream(baos);
-               ZipEntry entry = new ZipEntry("zip");
-               entry.setSize(input.length);
-               zos.putNextEntry(entry);
-               zos.write(input);
-               zos.closeEntry();
-               zos.close();
+               try (ZipOutputStream zos = new ZipOutputStream(baos)) {
+                       ZipEntry entry = new ZipEntry("zip");
+                       entry.setSize(input.length);
+                       zos.putNextEntry(entry);
+                       zos.write(input);
+                       zos.closeEntry();
+                       zos.close();
+               }
                return baos.toByteArray();
        }