close input streams for parts

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1896463 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2021-12-28 02:42:29 +00:00
parent 22d162cc7d
commit 90319df180
9 changed files with 28 additions and 19 deletions

View File

@ -18,6 +18,7 @@
package org.apache.poi.xdgf.usermodel;
import java.io.IOException;
import java.io.InputStream;
import com.microsoft.schemas.office.visio.x2012.main.MasterContentsDocument;
import org.apache.poi.ooxml.POIXMLException;
@ -44,8 +45,8 @@ public class XDGFMasterContents extends XDGFBaseContents {
try {
try {
_pageContents = MasterContentsDocument.Factory.parse(getPackagePart().getInputStream()).getMasterContents();
try (InputStream stream = getPackagePart().getInputStream()) {
_pageContents = MasterContentsDocument.Factory.parse(stream).getMasterContents();
} catch (XmlException | IOException e) {
throw new POIXMLException(e);
}

View File

@ -18,6 +18,7 @@
package org.apache.poi.xdgf.usermodel;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
@ -59,8 +60,8 @@ public class XDGFMasters extends XDGFXMLDocumentPart {
@Override
protected void onDocumentRead() {
try {
try {
_mastersObject = MastersDocument.Factory.parse(getPackagePart().getInputStream()).getMasters();
try (InputStream stream = getPackagePart().getInputStream()) {
_mastersObject = MastersDocument.Factory.parse(stream).getMasters();
} catch (XmlException | IOException e) {
throw new POIXMLException(e);
}

View File

@ -18,6 +18,7 @@
package org.apache.poi.xdgf.usermodel;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
@ -43,8 +44,8 @@ public class XDGFPageContents extends XDGFBaseContents {
@Override
protected void onDocumentRead() {
try {
try {
_pageContents = PageContentsDocument.Factory.parse(getPackagePart().getInputStream()).getPageContents();
try (InputStream stream = getPackagePart().getInputStream()) {
_pageContents = PageContentsDocument.Factory.parse(stream).getPageContents();
} catch (XmlException | IOException e) {
throw new POIXMLException(e);
}

View File

@ -17,6 +17,7 @@
package org.apache.poi.xdgf.usermodel;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@ -58,8 +59,8 @@ public class XDGFPages extends XDGFXMLDocumentPart {
@Override
protected void onDocumentRead() {
try {
try {
_pagesObject = PagesDocument.Factory.parse(getPackagePart().getInputStream()).getPages();
try (InputStream stream = getPackagePart().getInputStream()) {
_pagesObject = PagesDocument.Factory.parse(stream).getPages();
} catch (XmlException | IOException e) {
throw new POIXMLException(e);
}

View File

@ -64,8 +64,8 @@ public class XmlVisioDocument extends POIXMLDocument {
VisioDocumentType document;
try {
document = VisioDocumentDocument1.Factory.parse(getPackagePart().getInputStream()).getVisioDocument();
try (InputStream stream = getPackagePart().getInputStream()){
document = VisioDocumentDocument1.Factory.parse(stream).getVisioDocument();
} catch (XmlException | IOException e) {
throw new POIXMLException(e);
}

View File

@ -85,8 +85,8 @@ public final class XSLFPictureData extends POIXMLDocumentPart implements Picture
* @return the Picture data.
*/
public byte[] getData() {
try {
return IOUtils.toByteArray(getInputStream());
try (InputStream stream = getInputStream()) {
return IOUtils.toByteArray(stream);
} catch (IOException e) {
throw new POIXMLException(e);
}

View File

@ -60,8 +60,10 @@ public class XSSFBHyperlinksTable {
//load the urls from the sheet .rels
loadUrlsFromSheetRels(sheetPart);
//now load the hyperlinks from the bottom of the sheet
HyperlinkSheetScraper scraper = new HyperlinkSheetScraper(sheetPart.getInputStream());
scraper.parse();
try (InputStream stream = sheetPart.getInputStream()) {
HyperlinkSheetScraper scraper = new HyperlinkSheetScraper(stream);
scraper.parse();
}
}
/**

View File

@ -111,8 +111,9 @@ public class XSSFBReader extends XSSFReader {
if(parts.size() == 0) return null;
// Create the Styles Table, and associate the Themes if present
return new XSSFBStylesTable(parts.get(0).getInputStream());
try (InputStream stream = parts.get(0).getInputStream()) {
return new XSSFBStylesTable(stream);
}
}
public static class SheetIterator extends XSSFReader.SheetIterator {
@ -133,9 +134,11 @@ public class XSSFBReader extends XSSFReader {
@Override
protected Iterator<XSSFSheetRef> createSheetIteratorFromWB(PackagePart wb) throws IOException {
SheetRefLoader sheetRefLoader = new SheetRefLoader(wb.getInputStream());
sheetRefLoader.parse();
return sheetRefLoader.getSheets().iterator();
try (InputStream stream = wb.getInputStream()) {
SheetRefLoader sheetRefLoader = new SheetRefLoader(stream);
sheetRefLoader.parse();
return sheetRefLoader.getSheets().iterator();
}
}
/**

Binary file not shown.