Close resource leak in Zip
@@ -57,22 +57,23 @@ private static void addToZip(String basePath, ZipOutputStream zos, File toAdd) t
}
}
} else {
- FileInputStream fis = new FileInputStream(toAdd);
+ try (FileInputStream fis = new FileInputStream(toAdd)) {
String name = toAdd.getAbsolutePath().substring(basePath.length() + 1);
ZipEntry entry = new ZipEntry(name.replace('\\', '/'));
zos.putNextEntry(entry);
+
int len;
byte[] buffer = new byte[4096];
while ((len = fis.read(buffer)) != -1) {
zos.write(buffer, 0, len);
}
- fis.close();
zos.closeEntry();
}
}
+ }
public static File unzipToTempDir(String source, String prefix, String suffix) throws IOException {
File output = TemporaryFilesystem.getDefaultTmpFS().createTempDir(prefix, suffix);
