Skip to content

Commit

Permalink
Ensure ByteOutputStream is auto closed.
Browse files Browse the repository at this point in the history
  • Loading branch information
dds14002 committed Mar 3, 2020
1 parent bdc0eb5 commit ddbb7b8
Showing 1 changed file with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,21 @@ public Map<String, byte[]> getSmgXmlEntry(byte[] data) {

@Nullable
public byte[] repackageSmg(Map<String, byte[]> entryMap) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try (ZipOutputStream zos = new ZipOutputStream(bos)) {
for(Map.Entry<String, byte[]> entry : entryMap.entrySet()) {
ZipEntry zipEntry = new ZipEntry(entry.getKey());
zos.putNextEntry(zipEntry);
zos.write(entry.getValue());
zos.closeEntry();
try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
try (ZipOutputStream zos = new ZipOutputStream(bos)) {
for(Map.Entry<String, byte[]> entry : entryMap.entrySet()) {
ZipEntry zipEntry = new ZipEntry(entry.getKey());
zos.putNextEntry(zipEntry);
zos.write(entry.getValue());
zos.closeEntry();
}
}
return bos.toByteArray();
} catch (IOException e) {
log.error("Failed to repackage smg file");
e.printStackTrace();
return null;
}

return bos.toByteArray();

}

}

0 comments on commit ddbb7b8

Please sign in to comment.