sonar fix:Resources handling in Gunzip 87/34687/1
authorajay priyadarshi <ajay.priyadarshi@ril.com>
Thu, 8 Mar 2018 06:50:59 +0000 (12:20 +0530)
committerajay priyadarshi <ajay.priyadarshi@ril.com>
Thu, 8 Mar 2018 06:50:59 +0000 (12:20 +0530)
emsdriver/commons/utils/Gunzip.java
file name: Gunzip.java

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

index a24afbe..89aa731 100644 (file)
@@ -24,20 +24,13 @@ public class Gunzip {
         *
         */
        public void unCompress(String gzFileName, String toFile) throws IOException {
-               try {
-                       FileInputStream gzInput = new FileInputStream(gzFileName);
-                       GZIPInputStream gzIn = new GZIPInputStream(gzInput);
+               try (   FileInputStream gzInput = new FileInputStream(gzFileName);
+                       GZIPInputStream gzIn = new GZIPInputStream(gzInput)){
                        File tofile = new File(toFile);
                        enable(tofile);
-                       FileOutputStream fileOutput = new FileOutputStream(tofile, false);
-                       try{
+                       try(FileOutputStream fileOutput = new FileOutputStream(tofile, false)){
                                moveBytes(gzIn, fileOutput, -1, -1, 1024);
-                       } finally {
-                               gzInput.close();
-                               gzIn.close();
-                               fileOutput.close();
-                       }
-
+                       } 
                }catch(IOException e){
                throw e;
                }