This is an automated email from the ASF dual-hosted git repository.
coheigea pushed a commit to branch 3.6.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git
The following commit(s) were added to refs/heads/3.6.x-fixes by this push:
new 049fd12e935 Reset CachedWriter.cosClosed when opening a new temp file
writer (#3780)
049fd12e935 is described below
commit 049fd12e935f0d6b8a4e0ca90937688b705026f8
Author: Colm O hEigeartaigh <[email protected]>
AuthorDate: Wed Nov 25 16:07:12 2026 +0000
Reset CachedWriter.cosClosed when opening a new temp file writer (#3780)
(cherry picked from commit ff9ea03911de461c5ef505ef1c0c226fb23b08be)
---
.../main/java/org/apache/cxf/io/CachedWriter.java | 2 ++
.../java/org/apache/cxf/io/CachedWriterTest.java | 27 +++++++++++++++++++++-
2 files changed, 28 insertions(+), 1 deletion(-)
diff --git a/core/src/main/java/org/apache/cxf/io/CachedWriter.java
b/core/src/main/java/org/apache/cxf/io/CachedWriter.java
index 01785631def..1aabf45a854 100644
--- a/core/src/main/java/org/apache/cxf/io/CachedWriter.java
+++ b/core/src/main/java/org/apache/cxf/io/CachedWriter.java
@@ -611,6 +611,8 @@ public class CachedWriter extends Writer {
}
private OutputStreamWriter createOutputStreamWriter(File file) throws
IOException {
+ // a new file writer is being opened; the previous one (if any) may
have been closed
+ cosClosed = false;
OutputStream out = new
BufferedOutputStream(Files.newOutputStream(file.toPath()));
if (cipherTransformation != null) {
try {
diff --git a/core/src/test/java/org/apache/cxf/io/CachedWriterTest.java
b/core/src/test/java/org/apache/cxf/io/CachedWriterTest.java
index e15b78da2f4..8ffcda03e3e 100644
--- a/core/src/test/java/org/apache/cxf/io/CachedWriterTest.java
+++ b/core/src/test/java/org/apache/cxf/io/CachedWriterTest.java
@@ -23,6 +23,13 @@ import java.io.IOException;
import java.io.Reader;
import java.io.StringWriter;
+import org.apache.cxf.helpers.IOUtils;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
public class CachedWriterTest extends CachedStreamTestBase {
@Override
protected void reloadDefaultProperties() {
@@ -81,6 +88,24 @@ public class CachedWriterTest extends CachedStreamTestBase {
protected String readPartiallyFromStreamObject(Object cache, int len)
throws IOException {
return readPartiallyFromReader((Reader)cache, len);
}
-}
+ @Test
+ public void testSpillToFileAgainAfterResetOut() throws IOException {
+ CachedWriter cw = new CachedWriter();
+ cw.setThreshold(16);
+ String first = "first-content-that-exceeds-the-threshold";
+ cw.write(first);
+ assertNotNull("first write should have spilled to a temp file",
cw.getTempFile());
+ // closes the file writer and moves the content back in memory
+ cw.resetOut(null, true);
+
+ String second = "second-content-that-exceeds-the-threshold";
+ cw.write(second);
+ assertNotNull("second write should have spilled to a temp file",
cw.getTempFile());
+ try (Reader r = cw.getReader()) {
+ assertEquals(first + second, IOUtils.toString(r));
+ }
+ cw.close();
+ }
+}