Browse Source

bug 60153: findbugs OBL_UNSATISFIED_OBLIGATION_EXCEPTION_EDGE close opened streams if an exception is raised while decorating the stream

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1763959 13f79535-47bb-0310-9956-ffa450edef68
tags/REL_3_16_BETA1
Javen O'Neal 7 years ago
parent
commit
ad360c8e46
1 changed files with 17 additions and 3 deletions
  1. 17
    3
      src/ooxml/java/org/apache/poi/xssf/streaming/SheetDataWriter.java

+ 17
- 3
src/ooxml/java/org/apache/poi/xssf/streaming/SheetDataWriter.java View File

@@ -92,8 +92,16 @@ public class SheetDataWriter {
* @param fd the file to write to
*/
public Writer createWriter(File fd) throws IOException {
final OutputStream decorated = decorateOutputStream(new FileOutputStream(fd));
return new BufferedWriter(new OutputStreamWriter(decorated, "UTF-8"));
FileOutputStream fos = new FileOutputStream(fd);
OutputStream decorated;
try {
decorated = decorateOutputStream(fos);
} catch (final IOException e) {
fos.close();
throw e;
}
return new BufferedWriter(
new OutputStreamWriter(decorated, "UTF-8"));
}
/**
@@ -128,7 +136,13 @@ public class SheetDataWriter {
*/
public InputStream getWorksheetXMLInputStream() throws IOException {
File fd = getTempFile();
return decorateInputStream(new FileInputStream(fd));
FileInputStream fis = new FileInputStream(fd);
try {
return decorateInputStream(fis);
} catch (IOException e) {
fis.close();
throw e;
}
}
/**

Loading…
Cancel
Save