use try with resources

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1818781 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2017-12-20 11:47:52 +00:00
parent 57dcaedde7
commit 7cdaeba856

View 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;
}