Skip to content

Commit

Permalink
bug fix: zipFiles mothods update (#703)
Browse files Browse the repository at this point in the history
  • Loading branch information
yangaobiao committed Dec 10, 2020
1 parent e786b9a commit d666259
Showing 1 changed file with 8 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -369,47 +369,21 @@ public String genPemFile() throws BrokerException {
}

private static void zipFiles(File[] srcFiles, File zipFile) throws IOException {
byte[] buf = new byte[1024];
if (!zipFile.exists()) {
try {
zipFile.createNewFile();
} catch (IOException e) {
throw new IOException();
}
zipFile.createNewFile();
}
FileOutputStream fileOutputStream = null;
ZipOutputStream zipOutputStream = null;
try {
fileOutputStream = new FileOutputStream(zipFile);
zipOutputStream = new ZipOutputStream(fileOutputStream);
try (FileOutputStream fileOutPutStream = new FileOutputStream(zipFile); ZipOutputStream zipOutPutStream = new ZipOutputStream(fileOutPutStream)) {
for (int i = 0; i < srcFiles.length; i++) {
FileInputStream fileInputStream = null;
ZipEntry zipEntry = null;
try {
fileInputStream = new FileInputStream(srcFiles[i]);
zipEntry = new ZipEntry(srcFiles[i].getName());
zipOutputStream.putNextEntry(zipEntry);
try (FileInputStream fileInputStream = new FileInputStream(srcFiles[i])) {
zipOutPutStream.putNextEntry(new ZipEntry(srcFiles[i].getName()));
int len;
byte[] buffer = new byte[1024];
while ((len = fileInputStream.read(buffer)) > 0) {
zipOutputStream.write(buffer, 0, len);
}
} finally {
if (null != fileInputStream) {
fileInputStream.close();
}
if (zipOutputStream != null){
zipOutputStream.closeEntry();
while ((len = fileInputStream.read(buf)) > 0) {
zipOutPutStream.write(buf, 0, len);
}
zipOutPutStream.closeEntry();
}
}
} finally {
if (fileOutputStream != null) {
fileOutputStream.close();
}
if (zipOutputStream != null) {
zipOutputStream.close();
}

}
}

Expand Down

0 comments on commit d666259

Please sign in to comment.