mirror of
https://github.com/apache/poi.git
synced 2026-02-27 20:40:08 +08:00
use try block to close input streams
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1895203 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
0825c7a4f8
commit
deab188437
@ -464,8 +464,11 @@ public abstract class OPCPackage implements RelationshipSource, Closeable {
|
||||
closeImpl();
|
||||
}
|
||||
} else if (this.output != null) {
|
||||
save(this.output);
|
||||
output.close();
|
||||
try {
|
||||
save(this.output);
|
||||
} finally {
|
||||
output.close();
|
||||
}
|
||||
}
|
||||
|
||||
// ensure all held resources are freed
|
||||
|
||||
@ -182,9 +182,9 @@ public final class XSLFPictureData extends POIXMLDocumentPart implements Picture
|
||||
}
|
||||
|
||||
public void setData(byte[] data) throws IOException {
|
||||
OutputStream os = getPackagePart().getOutputStream();
|
||||
os.write(data);
|
||||
os.close();
|
||||
try (OutputStream os = getPackagePart().getOutputStream()) {
|
||||
os.write(data);
|
||||
}
|
||||
// recalculate now since we already have the data bytes available anyhow
|
||||
checksum = IOUtils.calculateChecksum(data);
|
||||
|
||||
|
||||
@ -61,11 +61,14 @@ public class PDFFormat implements OutputFormat {
|
||||
|
||||
@Override
|
||||
public void writeSlide(MFProxy proxy, File outFile) throws IOException {
|
||||
pdfBoxGraphics2D.dispose();
|
||||
try {
|
||||
pdfBoxGraphics2D.dispose();
|
||||
|
||||
PDFormXObject appearanceStream = pdfBoxGraphics2D.getXFormObject();
|
||||
contentStream.drawForm(appearanceStream);
|
||||
contentStream.close();
|
||||
PDFormXObject appearanceStream = pdfBoxGraphics2D.getXFormObject();
|
||||
contentStream.drawForm(appearanceStream);
|
||||
} finally {
|
||||
contentStream.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -75,9 +78,12 @@ public class PDFFormat implements OutputFormat {
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
document.close();
|
||||
if (fontTextDrawer != null) {
|
||||
fontTextDrawer.close();
|
||||
try {
|
||||
document.close();
|
||||
} finally {
|
||||
if (fontTextDrawer != null) {
|
||||
fontTextDrawer.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -115,28 +115,28 @@ public class XSSFBEventBasedExcelExtractor extends XSSFEventBasedExcelExtractor
|
||||
SheetTextExtractor sheetExtractor = new SheetTextExtractor();
|
||||
XSSFBHyperlinksTable hyperlinksTable = null;
|
||||
while (iter.hasNext()) {
|
||||
InputStream stream = iter.next();
|
||||
if (getIncludeSheetNames()) {
|
||||
text.append(iter.getSheetName());
|
||||
text.append('\n');
|
||||
try (InputStream stream = iter.next()) {
|
||||
if (getIncludeSheetNames()) {
|
||||
text.append(iter.getSheetName());
|
||||
text.append('\n');
|
||||
}
|
||||
if (handleHyperlinksInCells) {
|
||||
hyperlinksTable = new XSSFBHyperlinksTable(iter.getSheetPart());
|
||||
}
|
||||
XSSFBCommentsTable comments = getIncludeCellComments() ? iter.getXSSFBSheetComments() : null;
|
||||
processSheet(sheetExtractor, styles, comments, strings, stream);
|
||||
if (getIncludeHeadersFooters()) {
|
||||
sheetExtractor.appendHeaderText(text);
|
||||
}
|
||||
sheetExtractor.appendCellText(text);
|
||||
if (getIncludeTextBoxes()) {
|
||||
processShapes(iter.getShapes(), text);
|
||||
}
|
||||
if (getIncludeHeadersFooters()) {
|
||||
sheetExtractor.appendFooterText(text);
|
||||
}
|
||||
sheetExtractor.reset();
|
||||
}
|
||||
if (handleHyperlinksInCells) {
|
||||
hyperlinksTable = new XSSFBHyperlinksTable(iter.getSheetPart());
|
||||
}
|
||||
XSSFBCommentsTable comments = getIncludeCellComments() ? iter.getXSSFBSheetComments() : null;
|
||||
processSheet(sheetExtractor, styles, comments, strings, stream);
|
||||
if (getIncludeHeadersFooters()) {
|
||||
sheetExtractor.appendHeaderText(text);
|
||||
}
|
||||
sheetExtractor.appendCellText(text);
|
||||
if (getIncludeTextBoxes()) {
|
||||
processShapes(iter.getShapes(), text);
|
||||
}
|
||||
if (getIncludeHeadersFooters()) {
|
||||
sheetExtractor.appendFooterText(text);
|
||||
}
|
||||
sheetExtractor.reset();
|
||||
stream.close();
|
||||
}
|
||||
|
||||
return text.toString();
|
||||
|
||||
@ -267,25 +267,25 @@ public class XSSFEventBasedExcelExtractor
|
||||
SheetTextExtractor sheetExtractor = new SheetTextExtractor();
|
||||
|
||||
while (iter.hasNext()) {
|
||||
InputStream stream = iter.next();
|
||||
if (includeSheetNames) {
|
||||
text.append(iter.getSheetName());
|
||||
text.append('\n');
|
||||
try (InputStream stream = iter.next()) {
|
||||
if (includeSheetNames) {
|
||||
text.append(iter.getSheetName());
|
||||
text.append('\n');
|
||||
}
|
||||
Comments comments = includeCellComments ? iter.getSheetComments() : null;
|
||||
processSheet(sheetExtractor, styles, comments, strings, stream);
|
||||
if (includeHeadersFooters) {
|
||||
sheetExtractor.appendHeaderText(text);
|
||||
}
|
||||
sheetExtractor.appendCellText(text);
|
||||
if (includeTextBoxes) {
|
||||
processShapes(iter.getShapes(), text);
|
||||
}
|
||||
if (includeHeadersFooters) {
|
||||
sheetExtractor.appendFooterText(text);
|
||||
}
|
||||
sheetExtractor.reset();
|
||||
}
|
||||
Comments comments = includeCellComments ? iter.getSheetComments() : null;
|
||||
processSheet(sheetExtractor, styles, comments, strings, stream);
|
||||
if (includeHeadersFooters) {
|
||||
sheetExtractor.appendHeaderText(text);
|
||||
}
|
||||
sheetExtractor.appendCellText(text);
|
||||
if (includeTextBoxes) {
|
||||
processShapes(iter.getShapes(), text);
|
||||
}
|
||||
if (includeHeadersFooters) {
|
||||
sheetExtractor.appendFooterText(text);
|
||||
}
|
||||
sheetExtractor.reset();
|
||||
stream.close();
|
||||
}
|
||||
|
||||
return text.toString();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user