kylin-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From liy...@apache.org
Subject [03/13] kylin git commit: KYLIN-2051 Fix potentially ineffective call in ZipFileUtils class
Date Mon, 10 Oct 2016 13:56:20 GMT
KYLIN-2051 Fix potentially ineffective call in ZipFileUtils class


Project: http://git-wip-us.apache.org/repos/asf/kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/ebc08484
Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/ebc08484
Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/ebc08484

Branch: refs/heads/yang21-cdh5.7
Commit: ebc08484a0575aaa77ebe67cc2a33a6935ea62e5
Parents: 2abf2d3
Author: lidongsjtu <lidong@apache.org>
Authored: Fri Oct 7 18:22:39 2016 +0800
Committer: lidongsjtu <lidong@apache.org>
Committed: Fri Oct 7 18:23:19 2016 +0800

----------------------------------------------------------------------
 .../apache/kylin/common/util/ZipFileUtils.java  | 57 ++++++++++++--------
 1 file changed, 34 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kylin/blob/ebc08484/core-common/src/main/java/org/apache/kylin/common/util/ZipFileUtils.java
----------------------------------------------------------------------
diff --git a/core-common/src/main/java/org/apache/kylin/common/util/ZipFileUtils.java b/core-common/src/main/java/org/apache/kylin/common/util/ZipFileUtils.java
index 525a34c..ef24d85 100644
--- a/core-common/src/main/java/org/apache/kylin/common/util/ZipFileUtils.java
+++ b/core-common/src/main/java/org/apache/kylin/common/util/ZipFileUtils.java
@@ -38,32 +38,41 @@ public class ZipFileUtils {
         if (!validateZipFilename(zipFilename)) {
             throw new RuntimeException("Zipfile must end with .zip");
         }
-        ZipOutputStream zipFile = new ZipOutputStream(new FileOutputStream(zipFilename));
-        compressDirectoryToZipfile(normDir(new File(sourceDir).getParent()), normDir(sourceDir),
zipFile);
-        IOUtils.closeQuietly(zipFile);
+        ZipOutputStream zipFile = null;
+        try {
+            zipFile = new ZipOutputStream(new FileOutputStream(zipFilename));
+            compressDirectoryToZipfile(normDir(new File(sourceDir).getParent()), normDir(sourceDir),
zipFile);
+        } finally {
+            IOUtils.closeQuietly(zipFile);
+        }
     }
 
     public static void decompressZipfileToDirectory(String zipFileName, File outputFolder)
throws IOException {
+        ZipInputStream zipInputStream = null;
+        try {
+            zipInputStream = new ZipInputStream(new FileInputStream(zipFileName));
+            ZipEntry zipEntry = null;
+            while ((zipEntry = zipInputStream.getNextEntry()) != null) {
+                logger.info("decompressing " + zipEntry.getName() + " is directory:" + zipEntry.isDirectory()
+ " available: " + zipInputStream.available());
 
-        ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream(zipFileName));
-        ZipEntry zipEntry = null;
-        while ((zipEntry = zipInputStream.getNextEntry()) != null) {
-            logger.info("decompressing " + zipEntry.getName() + " is directory:" + zipEntry.isDirectory()
+ " available: " + zipInputStream.available());
-
-            File temp = new File(outputFolder, zipEntry.getName());
-            if (zipEntry.isDirectory()) {
-                temp.mkdirs();
-            } else {
-                temp.getParentFile().mkdirs();
-                temp.createNewFile();
-                temp.setLastModified(zipEntry.getTime());
-                FileOutputStream outputStream = new FileOutputStream(temp);
-                IOUtils.copy(zipInputStream, outputStream);
-                IOUtils.closeQuietly(outputStream);
+                File temp = new File(outputFolder, zipEntry.getName());
+                if (zipEntry.isDirectory()) {
+                    temp.mkdirs();
+                } else {
+                    temp.getParentFile().mkdirs();
+                    temp.createNewFile();
+                    temp.setLastModified(zipEntry.getTime());
+                    FileOutputStream outputStream = new FileOutputStream(temp);
+                    try {
+                        IOUtils.copy(zipInputStream, outputStream);
+                    } finally {
+                        IOUtils.closeQuietly(outputStream);
+                    }
+                }
             }
+        } finally {
+            IOUtils.closeQuietly(zipInputStream);
         }
-        IOUtils.closeQuietly(zipInputStream);
-
     }
 
     private static void compressDirectoryToZipfile(String rootDir, String sourceDir, ZipOutputStream
out) throws IOException {
@@ -74,10 +83,12 @@ public class ZipFileUtils {
                 ZipEntry entry = new ZipEntry(normDir(StringUtils.isEmpty(rootDir) ? sourceDir
: sourceDir.replace(rootDir, "")) + sourceFile.getName());
                 entry.setTime(sourceFile.lastModified());
                 out.putNextEntry(entry);
-
                 FileInputStream in = new FileInputStream(sourceDir + sourceFile.getName());
-                IOUtils.copy(in, out);
-                IOUtils.closeQuietly(in);
+                try {
+                    IOUtils.copy(in, out);
+                } finally {
+                    IOUtils.closeQuietly(in);
+                }
             }
         }
     }


Mime
View raw message