Repository: flink
Updated Branches:
  refs/heads/master c869eb9d1 -> 9f54f6b5f


[FLINK-8146][py] Properly close ZipInputStream

This closes #5349.


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

Branch: refs/heads/master
Commit: 9f54f6b5f2ab85397ba6dd720baa2ddf69cc7024
Parents: c869eb9
Author: zentol <[email protected]>
Authored: Wed Jan 24 11:56:25 2018 +0100
Committer: zentol <[email protected]>
Committed: Thu Jan 25 12:10:12 2018 +0100

----------------------------------------------------------------------
 .../flink/python/api/PythonPlanBinder.java      | 38 ++++++++++----------
 1 file changed, 19 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flink/blob/9f54f6b5/flink-libraries/flink-python/src/main/java/org/apache/flink/python/api/PythonPlanBinder.java
----------------------------------------------------------------------
diff --git 
a/flink-libraries/flink-python/src/main/java/org/apache/flink/python/api/PythonPlanBinder.java
 
b/flink-libraries/flink-python/src/main/java/org/apache/flink/python/api/PythonPlanBinder.java
index e4aa518..106ac7a 100644
--- 
a/flink-libraries/flink-python/src/main/java/org/apache/flink/python/api/PythonPlanBinder.java
+++ 
b/flink-libraries/flink-python/src/main/java/org/apache/flink/python/api/PythonPlanBinder.java
@@ -215,29 +215,29 @@ public class PythonPlanBinder {
        private static void unzipPythonLibrary(Path targetDir) throws 
IOException {
                FileSystem targetFs = targetDir.getFileSystem();
                ClassLoader classLoader = 
PythonPlanBinder.class.getClassLoader();
-               ZipInputStream zis = new 
ZipInputStream(classLoader.getResourceAsStream("python-source.zip"));
-               ZipEntry entry = zis.getNextEntry();
-               while (entry != null) {
-                       String fileName = entry.getName();
-                       Path newFile = new Path(targetDir, fileName);
-                       if (entry.isDirectory()) {
-                               targetFs.mkdirs(newFile);
-                       } else {
-                               try {
-                                       LOG.debug("Unzipping to {}.", newFile);
-                                       FSDataOutputStream fsDataOutputStream = 
targetFs.create(newFile, FileSystem.WriteMode.NO_OVERWRITE);
-                                       IOUtils.copyBytes(zis, 
fsDataOutputStream, false);
-                               } catch (Exception e) {
-                                       zis.closeEntry();
-                                       zis.close();
-                                       throw new IOException("Failed to unzip 
flink python library.", e);
+               try (ZipInputStream zis = new 
ZipInputStream(classLoader.getResourceAsStream("python-source.zip"))) {
+                       ZipEntry entry = zis.getNextEntry();
+                       while (entry != null) {
+                               String fileName = entry.getName();
+                               Path newFile = new Path(targetDir, fileName);
+                               if (entry.isDirectory()) {
+                                       targetFs.mkdirs(newFile);
+                               } else {
+                                       try {
+                                               LOG.debug("Unzipping to {}.", 
newFile);
+                                               FSDataOutputStream 
fsDataOutputStream = targetFs.create(newFile, 
FileSystem.WriteMode.NO_OVERWRITE);
+                                               IOUtils.copyBytes(zis, 
fsDataOutputStream, false);
+                                       } catch (Exception e) {
+                                               zis.closeEntry();
+                                               throw new IOException("Failed 
to unzip flink python library.", e);
+                                       }
                                }
-                       }
 
+                               zis.closeEntry();
+                               entry = zis.getNextEntry();
+                       }
                        zis.closeEntry();
-                       entry = zis.getNextEntry();
                }
-               zis.closeEntry();
        }
 
        
//=====Setup========================================================================================================

Reply via email to