]> source.dussan.org Git - poi.git/commitdiff
use try with resources
authorPJ Fanning <fanningpj@apache.org>
Wed, 20 Dec 2017 11:47:52 +0000 (11:47 +0000)
committerPJ Fanning <fanningpj@apache.org>
Wed, 20 Dec 2017 11:47:52 +0000 (11:47 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1818781 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java

index 1a027fea00089021e23cf4f4a1bf08fe91a55ea7..aa1ffd20d2168cf811a2698681a717238fa4fb14 100644 (file)
@@ -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;
     }