use try block to close input streams

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1895202 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2021-11-20 13:43:27 +00:00
parent 363abd6efe
commit 0825c7a4f8
2 changed files with 9 additions and 8 deletions

View File

@ -143,9 +143,9 @@ public class CryptoAPIEncryptor extends Encryptor {
descEntry.reserved2 = 0;
bos.setBlock(block);
DocumentInputStream dis = dir.createDocumentInputStream(entry);
IOUtils.copy(dis, bos);
dis.close();
try (DocumentInputStream dis = dir.createDocumentInputStream(entry)) {
IOUtils.copy(dis, bos);
}
descEntry.streamSize = bos.size() - descEntry.streamOffset;
descList.add(descEntry);

View File

@ -85,11 +85,12 @@ public class BitmapImageRenderer implements ImageRenderer {
public void loadImage(InputStream data, String contentType) throws IOException {
InputStream in = data;
if (doCache) {
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
IOUtils.copy(data, bos);
cachedImage = bos.toByteArray();
cachedContentType = contentType;
in = bos.toInputStream();
try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
IOUtils.copy(data, bos);
cachedImage = bos.toByteArray();
cachedContentType = contentType;
in = bos.toInputStream();
}
}
img = readImage(in, contentType);
}