close input streams for parts

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1896464 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2021-12-28 02:48:28 +00:00
parent 90319df180
commit 2996f82e98
4 changed files with 12 additions and 5 deletions

View File

@ -36,6 +36,7 @@ import javax.xml.crypto.URIReference;
import javax.xml.crypto.URIReferenceException;
import javax.xml.crypto.XMLCryptoContext;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@ -81,7 +82,7 @@ public class OOXMLURIDereferencer implements URIDereferencer {
return baseUriDereferencer.dereference(uriReference, context);
}
InputStream dataStream;
InputStream dataStream = null;
try {
dataStream = part.getInputStream();
@ -99,6 +100,7 @@ public class OOXMLURIDereferencer implements URIDereferencer {
}
}
} catch (IOException e) {
IOUtils.closeQuietly(dataStream);
throw new URIReferenceException("I/O error: " + e.getMessage(), e);
}

View File

@ -68,8 +68,9 @@ public class XSSFBSharedStringsTable implements SharedStrings {
// Some workbooks have no shared strings table.
if (parts.size() > 0) {
PackagePart sstPart = parts.get(0);
readFrom(sstPart.getInputStream());
try (InputStream stream = sstPart.getInputStream()) {
readFrom(stream);
}
}
}

View File

@ -131,7 +131,9 @@ public class ReadOnlySharedStringsTable extends DefaultHandler implements Shared
// Some workbooks have no shared strings table.
if (parts.size() > 0) {
PackagePart sstPart = parts.get(0);
readFrom(sstPart.getInputStream());
try (InputStream stream = sstPart.getInputStream()) {
readFrom(stream);
}
}
}

View File

@ -165,7 +165,9 @@ public class XSSFBReader extends XSSFReader {
}
PackagePartName commentsName = PackagingURIHelper.createPartName(comments.getTargetURI());
PackagePart commentsPart = sheetPkg.getPackage().getPart(commentsName);
return new XSSFBCommentsTable(commentsPart.getInputStream());
try (InputStream stream = commentsPart.getInputStream()) {
return new XSSFBCommentsTable(stream);
}
}
} catch (InvalidFormatException | IOException e) {
return null;