flink-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ches...@apache.org
Subject flink git commit: [FLINK-4096] Ensure JarOutputStream is always closed
Date Mon, 11 Jul 2016 09:43:23 GMT
Repository: flink
Updated Branches:
  refs/heads/master 9178076db -> 8f6876218


[FLINK-4096] Ensure JarOutputStream is always closed

This closes #2172


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

Branch: refs/heads/master
Commit: 8f6876218bb1335e95ab04fc608ce21959889e57
Parents: 9178076
Author: Ivan Mushketyk <ivan.mushketik@gmail.com>
Authored: Mon Jun 27 22:30:08 2016 +0100
Committer: zentol <chesnay@apache.org>
Committed: Mon Jul 11 11:42:09 2016 +0200

----------------------------------------------------------------------
 .../flink/runtime/util/JarFileCreator.java      | 44 ++++++++++----------
 1 file changed, 22 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flink/blob/8f687621/flink-runtime/src/main/java/org/apache/flink/runtime/util/JarFileCreator.java
----------------------------------------------------------------------
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/util/JarFileCreator.java
b/flink-runtime/src/main/java/org/apache/flink/runtime/util/JarFileCreator.java
index c55a9dc..c877d74 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/util/JarFileCreator.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/util/JarFileCreator.java
@@ -189,33 +189,33 @@ public class JarFileCreator {
 			this.outputFile.delete();
 		}
 
-		final JarOutputStream jos = new JarOutputStream(new FileOutputStream(this.outputFile),
new Manifest());
-		final Iterator<Class<?>> it = this.classSet.iterator();
-		while (it.hasNext()) {
+		try ( JarOutputStream jos = new JarOutputStream(new FileOutputStream(this.outputFile),
new Manifest())) {
+			final Iterator<Class<?>> it = this.classSet.iterator();
+			while (it.hasNext()) {
 
-			final Class<?> clazz = it.next();
-			final String entry = clazz.getName().replace('.', '/') + CLASS_EXTENSION;
+				final Class<?> clazz = it.next();
+				final String entry = clazz.getName().replace('.', '/') + CLASS_EXTENSION;
 
-			jos.putNextEntry(new JarEntry(entry));
+				jos.putNextEntry(new JarEntry(entry));
 
-			String name = clazz.getName();
-			int n = name.lastIndexOf('.');
-			String className = null;
-			if (n > -1) {
-				className = name.substring(n + 1, name.length());
-			}
-			//Using the part after last dot instead of class.getSimpleName() could resolve the problem
of inner class.
-			final InputStream classInputStream = clazz.getResourceAsStream(className + CLASS_EXTENSION);
+				String name = clazz.getName();
+				int n = name.lastIndexOf('.');
+				String className = null;
+				if (n > -1) {
+					className = name.substring(n + 1, name.length());
+				}
+				//Using the part after last dot instead of class.getSimpleName() could resolve the problem
of inner class.
+				final InputStream classInputStream = clazz.getResourceAsStream(className + CLASS_EXTENSION);
 
-			int num = classInputStream.read(buf);
-			while (num != -1) {
-				jos.write(buf, 0, num);
-				num = classInputStream.read(buf);
-			}
+				int num = classInputStream.read(buf);
+				while (num != -1) {
+					jos.write(buf, 0, num);
+					num = classInputStream.read(buf);
+				}
 
-			classInputStream.close();
-			jos.closeEntry();
+				classInputStream.close();
+				jos.closeEntry();
+			}
 		}
-		jos.close();
 	}
 }


Mime
View raw message