cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ff...@apache.org
Subject cxf git commit: [CXF-6616]need always close the CipherOutputStream when the encryption is done to get the complete content
Date Tue, 29 Sep 2015 07:56:41 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.0.x-fixes 16fd4475d -> d644f01c6


[CXF-6616]need always close the CipherOutputStream when the encryption is done to get the
complete content

(cherry picked from commit 8eb78c3902bcf3a483aed26a838687a4ffb08bc7)


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/d644f01c
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/d644f01c
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/d644f01c

Branch: refs/heads/3.0.x-fixes
Commit: d644f01c65d9df3b6cf67fe0816e3ac54ada7ae3
Parents: 16fd447
Author: Freeman Fang <freeman.fang@gmail.com>
Authored: Tue Sep 29 15:55:11 2015 +0800
Committer: Freeman Fang <freeman.fang@gmail.com>
Committed: Tue Sep 29 15:56:27 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/d644f01c/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 b7693c3..3444c05 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) {
@@ -624,16 +631,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/d644f01c/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/d644f01c/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();
     }
 


Mime
View raw message