sonar fix: resources handling in Gunzip.java 85/32085/1
authorajay priyadarshi <ajay.priyadarshi@ril.com>
Mon, 19 Feb 2018 11:46:30 +0000 (17:16 +0530)
committerajay priyadarshi <ajay.priyadarshi@ril.com>
Mon, 19 Feb 2018 11:46:30 +0000 (17:16 +0530)
emsdriver/commons/utils/Gunzip.java
file name: Gunzip.java

Change-Id: I6a1e41bd2bee91bf87b06691f05f7cbc50b67973
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 9098c27..a24afbe 100644 (file)
@@ -24,24 +24,22 @@ public class Gunzip {
         *
         */
        public void unCompress(String gzFileName, String toFile) throws IOException {
-               GZIPInputStream gzIn = null;
-               FileOutputStream fileOutput = null;
-               FileInputStream gzInput = new FileInputStream(gzFileName);
                try {
-                       gzIn = new GZIPInputStream(gzInput);
+                       FileInputStream gzInput = new FileInputStream(gzFileName);
+                       GZIPInputStream gzIn = new GZIPInputStream(gzInput);
                        File tofile = new File(toFile);
                        enable(tofile);
-                       fileOutput = new FileOutputStream(tofile, false);
-
-                       moveBytes(gzIn, fileOutput, -1, -1, 1024);
-               } finally {
-                       if (gzIn != null) {
+                       FileOutputStream fileOutput = new FileOutputStream(tofile, false);
+                       try{
+                               moveBytes(gzIn, fileOutput, -1, -1, 1024);
+                       } finally {
+                               gzInput.close();
                                gzIn.close();
-                       }
-                       if (fileOutput != null) {
                                fileOutput.close();
                        }
 
+               }catch(IOException e){
+               throw e;
                }
 
        }
@@ -81,4 +79,4 @@ public class Gunzip {
                return totalNum;
        }
 
-}
\ No newline at end of file
+}