From 7cdaeba8567eb5d08de2117bfca85087df028eaa Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Wed, 20 Dec 2017 11:47:52 +0000 Subject: [PATCH] use try with resources git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1818781 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java index 1a027fea0..aa1ffd20d 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java @@ -544,9 +544,9 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook { public int addPicture(InputStream is, int format) throws IOException { int imageNumber = getAllPictures().size() + 1; XSSFPictureData img = createRelationship(XSSFPictureData.RELATIONS[format], XSSFFactory.getInstance(), imageNumber, true).getDocumentPart(); - OutputStream out = img.getPackagePart().getOutputStream(); - IOUtils.copy(is, out); - out.close(); + try (OutputStream out = img.getPackagePart().getOutputStream()) { + IOUtils.copy(is, out); + } pictures.add(img); return imageNumber - 1; }