mirror of https://github.com/apache/poi.git
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:
parent
537badf156
commit
943eb6b6cf
|
@ -544,9 +544,9 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook {
|
||||||
public int addPicture(InputStream is, int format) throws IOException {
|
public int addPicture(InputStream is, int format) throws IOException {
|
||||||
int imageNumber = getAllPictures().size() + 1;
|
int imageNumber = getAllPictures().size() + 1;
|
||||||
XSSFPictureData img = createRelationship(XSSFPictureData.RELATIONS[format], XSSFFactory.getInstance(), imageNumber, true).getDocumentPart();
|
XSSFPictureData img = createRelationship(XSSFPictureData.RELATIONS[format], XSSFFactory.getInstance(), imageNumber, true).getDocumentPart();
|
||||||
OutputStream out = img.getPackagePart().getOutputStream();
|
try (OutputStream out = img.getPackagePart().getOutputStream()) {
|
||||||
IOUtils.copy(is, out);
|
IOUtils.copy(is, out);
|
||||||
out.close();
|
}
|
||||||
pictures.add(img);
|
pictures.add(img);
|
||||||
return imageNumber - 1;
|
return imageNumber - 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue