Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion paimon-common/src/main/java/org/apache/paimon/fs/FileIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -378,10 +378,29 @@ default void writeFile(Path path, String content, boolean overwrite) throws IOEx
* implementations.
*/
default void overwriteFileUtf8(Path path, String content) throws IOException {
try (PositionOutputStream out = newOutputStream(path, true)) {
// Some FileIO implementations (e.g. HDFS) rethrow the exact same exception instance from
// close() that was already thrown from write(), which makes the try-with-resources
// suppression mechanism fail with "Self-suppression not permitted". Therefore close the
// stream manually and only add suppressed exceptions that differ from the primary one.
IOException primaryException = null;
PositionOutputStream out = newOutputStream(path, true);
try {
OutputStreamWriter writer = new OutputStreamWriter(out, StandardCharsets.UTF_8);
writer.write(content);
writer.flush();
} catch (IOException e) {
primaryException = e;
throw e;
} finally {
try {
out.close();
} catch (IOException closeException) {
if (primaryException == null) {
throw closeException;
} else if (primaryException != closeException) {
primaryException.addSuppressed(closeException);
}
}
}
}

Expand Down
Loading