sonar fix: resources handling in Zip.java 83/32083/1
authorajay priyadarshi <ajay.priyadarshi@ril.com>
Mon, 19 Feb 2018 11:30:53 +0000 (17:00 +0530)
committerajay priyadarshi <ajay.priyadarshi@ril.com>
Mon, 19 Feb 2018 11:30:53 +0000 (17:00 +0530)
emsdriver/commons/utils/Zip.java
file name: Zip.java

Change-Id: Iccd2ea69581b519b18016ed761ffb4811d9fe19e
Issue-ID: VFC-771
Signed-off-by: ajay priyadarshi <ajay.priyadarshi@ril.com>
ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/Zip.java

index 67f58fe..1d757a3 100644 (file)
@@ -92,15 +92,21 @@ public class Zip {
     }
 
     protected void compressFile(String absolutePath) throws IOException {
-        compressFileCount++;
-        byte byteBuf[] = new byte[2048];
-        zipOutput.putNextEntry(new ZipEntry(absolutePath.substring(relativeAddrIdx)));
-
-        FileInputStream input = new FileInputStream(absolutePath);
-        for (int count = 0; (count = input.read(byteBuf, 0, byteBuf.length)) != -1; )
-            zipOutput.write(byteBuf, 0, count);
-        input.close();
-        zipOutput.closeEntry();
+           try{
+                   compressFileCount++;
+                   byte byteBuf[] = new byte[2048];
+                   zipOutput.putNextEntry(new ZipEntry(absolutePath.substring(relativeAddrIdx)));
+                   FileInputStream input = new FileInputStream(absolutePath);
+                   try{
+                           for (int count = 0; (count = input.read(byteBuf, 0, byteBuf.length)) != -1; )
+                                   zipOutput.write(byteBuf, 0, count);
+                   }finally{
+                           input.close();
+                           zipOutput.closeEntry();
+                   }
+           }catch(IOException e){
+                   throw e;    
+           }           
     }
 
     public void setCompressLevel(int level) {