Browse Source

use try block to close input streams

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1895202 13f79535-47bb-0310-9956-ffa450edef68
tags/REL_5_2_0
PJ Fanning 2 years ago
parent
commit
0825c7a4f8

+ 3
- 3
poi/src/main/java/org/apache/poi/poifs/crypt/cryptoapi/CryptoAPIEncryptor.java 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);

+ 6
- 5
poi/src/main/java/org/apache/poi/sl/draw/BitmapImageRenderer.java 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);
}

Loading…
Cancel
Save