mirror of
https://github.com/apache/poi.git
synced 2026-02-27 20:40:08 +08:00
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:
parent
363abd6efe
commit
0825c7a4f8
@ -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);
|
||||
|
||||
@ -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…
x
Reference in New Issue
Block a user