Repository: cxf Updated Branches: refs/heads/master 84e90e647 -> 8eb78c390
[CXF-6616]need always close the CipherOutputStream when the encryption is done to get the complete content Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/8eb78c39 Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/8eb78c39 Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/8eb78c39 Branch: refs/heads/master Commit: 8eb78c3902bcf3a483aed26a838687a4ffb08bc7 Parents: 84e90e6 Author: Freeman Fang <[email protected]> Authored: Tue Sep 29 15:55:11 2015 +0800 Committer: Freeman Fang <[email protected]> Committed: Tue Sep 29 15:55:11 2015 +0800 ---------------------------------------------------------------------- .../java/org/apache/cxf/io/CachedWriter.java | 25 +++++++++++++++----- .../apache/cxf/io/CachedOutputStreamTest.java | 1 + .../org/apache/cxf/io/CachedWriterTest.java | 1 + 3 files changed, 21 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/8eb78c39/core/src/main/java/org/apache/cxf/io/CachedWriter.java ---------------------------------------------------------------------- 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 77b2266..ea18a54 100644 --- a/core/src/main/java/org/apache/cxf/io/CachedWriter.java +++ b/core/src/main/java/org/apache/cxf/io/CachedWriter.java @@ -52,6 +52,7 @@ public class CachedWriter extends Writer { private static int defaultThreshold; private static long defaultMaxSize; private static String defaultCipherTransformation; + static { String s = SystemPropertyAction.getPropertyOrNull("org.apache.cxf.io.CachedOutputStream.OutputDirectory"); @@ -78,6 +79,7 @@ public class CachedWriter extends Writer { protected boolean outputLocked; protected Writer currentStream; + private boolean cosClosed; private long threshold = defaultThreshold; private long maxSize = defaultMaxSize; @@ -176,7 +178,10 @@ public class CachedWriter extends Writer { } public void flush() throws IOException { - currentStream.flush(); + if (!cosClosed) { + currentStream.flush(); + } + if (null != callbacks) { for (CachedWriterCallback cb : callbacks) { cb.onFlush(this); @@ -220,7 +225,9 @@ public class CachedWriter extends Writer { } public void close() throws IOException { - currentStream.flush(); + if (!cosClosed) { + currentStream.flush(); + } outputLocked = true; if (null != callbacks) { for (CachedWriterCallback cb : callbacks) { @@ -601,16 +608,22 @@ public class CachedWriter extends Writer { throw new IOException(e.getMessage(), e); } out = new CipherOutputStream(out, ciphers.getEncryptor()) { - boolean closed; public void close() throws IOException { - if (!closed) { + if (!cosClosed) { super.close(); - closed = true; + cosClosed = true; } } }; } - return new OutputStreamWriter(out, "utf-8"); + return new OutputStreamWriter(out, "utf-8") { + public void close() throws IOException { + if (!cosClosed) { + super.close(); + cosClosed = true; + } + } + }; } private InputStreamReader createInputStreamReader(File file) throws IOException { http://git-wip-us.apache.org/repos/asf/cxf/blob/8eb78c39/core/src/test/java/org/apache/cxf/io/CachedOutputStreamTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/cxf/io/CachedOutputStreamTest.java b/core/src/test/java/org/apache/cxf/io/CachedOutputStreamTest.java index 1df7afb..b54c3cf 100644 --- a/core/src/test/java/org/apache/cxf/io/CachedOutputStreamTest.java +++ b/core/src/test/java/org/apache/cxf/io/CachedOutputStreamTest.java @@ -64,6 +64,7 @@ public class CachedOutputStreamTest extends CachedStreamTestBase { CachedOutputStream cos = (CachedOutputStream)cache; cos.write(result.getBytes("utf-8")); cos.flush(); + cos.getOut().close(); return cos.getTempFile(); } http://git-wip-us.apache.org/repos/asf/cxf/blob/8eb78c39/core/src/test/java/org/apache/cxf/io/CachedWriterTest.java ---------------------------------------------------------------------- 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 1f0bfdc..7a4c846 100644 --- a/core/src/test/java/org/apache/cxf/io/CachedWriterTest.java +++ b/core/src/test/java/org/apache/cxf/io/CachedWriterTest.java @@ -63,6 +63,7 @@ public class CachedWriterTest extends CachedStreamTestBase { CachedWriter cos = (CachedWriter)cache; cos.write(result); cos.flush(); + cos.getOut().close(); return cos.getTempFile(); }
