From 08143edf192780d2b70343d53d0db07967d774b2 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Wed, 3 May 2017 19:36:28 +0100 Subject: [PATCH] Close streams when unpacking the CLI See gh-9080 --- .../infrastructure/CommandLineInvoker.java | 33 ++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/spring-boot-cli/src/it/java/org/springframework/boot/cli/infrastructure/CommandLineInvoker.java b/spring-boot-cli/src/it/java/org/springframework/boot/cli/infrastructure/CommandLineInvoker.java index 14b16171195..8e73481bdc5 100644 --- a/spring-boot-cli/src/it/java/org/springframework/boot/cli/infrastructure/CommandLineInvoker.java +++ b/spring-boot-cli/src/it/java/org/springframework/boot/cli/infrastructure/CommandLineInvoker.java @@ -80,20 +80,31 @@ public final class CommandLineInvoker { })[0]; ZipInputStream input = new ZipInputStream(new FileInputStream(zip)); - ZipEntry entry; - while ((entry = input.getNextEntry()) != null) { - File file = new File(unpacked, entry.getName()); - if (entry.isDirectory()) { - file.mkdirs(); - } - else { - file.getParentFile().mkdirs(); - StreamUtils.copy(input, new FileOutputStream(file)); - if (entry.getName().endsWith("/bin/spring")) { - file.setExecutable(true); + try { + ZipEntry entry; + while ((entry = input.getNextEntry()) != null) { + File file = new File(unpacked, entry.getName()); + if (entry.isDirectory()) { + file.mkdirs(); + } + else { + file.getParentFile().mkdirs(); + FileOutputStream output = new FileOutputStream(file); + try { + StreamUtils.copy(input, output); + if (entry.getName().endsWith("/bin/spring")) { + file.setExecutable(true); + } + } + finally { + output.close(); + } } } } + finally { + input.close(); + } } File bin = new File(unpacked.listFiles()[0], "bin"); File launchScript = new File(bin, isWindows() ? "spring.bat" : "spring");