This is an automated email from the ASF dual-hosted git repository.
pjfanning pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/poi.git
The following commit(s) were added to refs/heads/trunk by this push:
new 04902719d1 Use try-with-resources for the PPTXMLDump output file
(#1253)
04902719d1 is described below
commit 04902719d1f9caab616a648b29ec9aa50c8e6b8f
Author: PJ Fanning <[email protected]>
AuthorDate: Mon Sep 7 13:26:39 2026 +0100
Use try-with-resources for the PPTXMLDump output file (#1253)
PPTXMLDump.main opened the .xml output stream and closed it only after
dump() returned, so an IOException part way through the dump leaked the
stream. Switch to try-with-resources.
While here: the console branch wrapped System.out in a BufferedWriter and
never flushed it, and dump() does not flush either, so running the tool
without -f printed nothing. Add the missing flush. System.out is
deliberately flushed rather than closed.
The now-unused java.io.OutputStream import is dropped.
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
---
.../main/java/org/apache/poi/hslf/dev/PPTXMLDump.java | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git
a/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/PPTXMLDump.java
b/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/PPTXMLDump.java
index d02506202a..fc710cf16f 100644
--- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/PPTXMLDump.java
+++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/PPTXMLDump.java
@@ -21,7 +21,6 @@ import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
-import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.nio.charset.StandardCharsets;
@@ -216,13 +215,16 @@ public final class PPTXMLDump {
System.out.println("Dumping " + arg);
if (outFile) {
- OutputStream fos =
Files.newOutputStream(Path.of(ppt.getName() + ".xml"));
- OutputStreamWriter out = new OutputStreamWriter(fos,
StandardCharsets.UTF_8);
- dump.dump(out);
- out.close();
+ try (Writer out = new OutputStreamWriter(
+ Files.newOutputStream(Path.of(ppt.getName() +
".xml")), StandardCharsets.UTF_8)) {
+ dump.dump(out);
+ }
} else {
- dump.dump(new BufferedWriter(
- new OutputStreamWriter(System.out,
StandardCharsets.UTF_8)));
+ Writer out = new BufferedWriter(
+ new OutputStreamWriter(System.out,
StandardCharsets.UTF_8));
+ dump.dump(out);
+ // dump() does not flush, and System.out must not be
closed here
+ out.flush();
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]