cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject [cxf] branch master updated: Make sure the CachedOutputStream output directory can also be set via a bus property
Date Tue, 29 May 2018 09:31:46 GMT
This is an automated email from the ASF dual-hosted git repository.

coheigea pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cxf.git


The following commit(s) were added to refs/heads/master by this push:
     new 7437a89  Make sure the CachedOutputStream output directory can also be set via a
bus property
7437a89 is described below

commit 7437a89a9c0fd3892863ab3fbaee6101b0d18851
Author: Colm O hEigeartaigh <coheigea@apache.org>
AuthorDate: Tue May 29 10:30:52 2018 +0100

    Make sure the CachedOutputStream output directory can also be set via a bus property
---
 core/src/main/java/org/apache/cxf/io/CachedConstants.java     |  6 ++++++
 core/src/main/java/org/apache/cxf/io/CachedOutputStream.java  | 11 +++++++++--
 core/src/main/java/org/apache/cxf/io/CachedWriter.java        | 11 +++++++++--
 .../test/java/org/apache/cxf/io/CachedOutputStreamTest.java   |  1 +
 .../src/test/java/org/apache/cxf/io/CachedStreamTestBase.java |  6 ++++++
 5 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/core/src/main/java/org/apache/cxf/io/CachedConstants.java b/core/src/main/java/org/apache/cxf/io/CachedConstants.java
index f8e32b7..24ba8d8 100644
--- a/core/src/main/java/org/apache/cxf/io/CachedConstants.java
+++ b/core/src/main/java/org/apache/cxf/io/CachedConstants.java
@@ -28,6 +28,12 @@ public final class CachedConstants {
         "org.apache.cxf.io.CachedOutputStream.OutputDirectory";
 
     /**
+     * The directory name for storing the temporary files. None is specified by default.
+     */
+    public static final String OUTPUT_DIRECTORY_BUS_PROP =
+        "bus.io.CachedOutputStream.OutputDirectory";
+
+    /**
      * The threshold value in bytes to switch from memory to file caching. The default value
is 128K for
      * CachedOutputStream and 64K for CachedWriter.
      */
diff --git a/core/src/main/java/org/apache/cxf/io/CachedOutputStream.java b/core/src/main/java/org/apache/cxf/io/CachedOutputStream.java
index b966ee4..bbdb49e 100644
--- a/core/src/main/java/org/apache/cxf/io/CachedOutputStream.java
+++ b/core/src/main/java/org/apache/cxf/io/CachedOutputStream.java
@@ -77,6 +77,8 @@ public class CachedOutputStream extends OutputStream {
 
     private long threshold = defaultThreshold;
     private long maxSize = defaultMaxSize;
+    private File outputDir = DEFAULT_TEMP_DIR;
+    private String cipherTransformation = defaultCipherTransformation;
 
     private long totalLength;
 
@@ -84,9 +86,7 @@ public class CachedOutputStream extends OutputStream {
 
     private boolean tempFileFailed;
     private File tempFile;
-    private File outputDir = DEFAULT_TEMP_DIR;
     private boolean allowDeleteOfFile = true;
-    private String cipherTransformation = defaultCipherTransformation;
     private CipherPair ciphers;
 
     private List<CachedOutputStreamCallback> callbacks;
@@ -119,6 +119,13 @@ public class CachedOutputStream extends OutputStream {
             if (v != null) {
                 cipherTransformation = v;
             }
+            v = getBusProperty(b, CachedConstants.OUTPUT_DIRECTORY_BUS_PROP, null);
+            if (v != null) {
+                File f = new File(v);
+                if (f.exists() && f.isDirectory()) {
+                    outputDir = f;
+                }
+            }
         }
     }
 
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 0f697a4..e3d67f4 100644
--- a/core/src/main/java/org/apache/cxf/io/CachedWriter.java
+++ b/core/src/main/java/org/apache/cxf/io/CachedWriter.java
@@ -83,6 +83,8 @@ public class CachedWriter extends Writer {
     private boolean cosClosed;
     private long threshold = defaultThreshold;
     private long maxSize = defaultMaxSize;
+    private File outputDir = DEFAULT_TEMP_DIR;
+    private String cipherTransformation = defaultCipherTransformation;
 
     private long totalLength;
 
@@ -90,9 +92,7 @@ public class CachedWriter extends Writer {
 
     private boolean tempFileFailed;
     private File tempFile;
-    private File outputDir = DEFAULT_TEMP_DIR;
     private boolean allowDeleteOfFile = true;
-    private String cipherTransformation = defaultCipherTransformation;
     private CipherPair ciphers;
 
     private List<CachedWriterCallback> callbacks;
@@ -138,6 +138,13 @@ public class CachedWriter extends Writer {
             if (v != null) {
                 cipherTransformation = v;
             }
+            v = getBusProperty(b, CachedConstants.OUTPUT_DIRECTORY_BUS_PROP, null);
+            if (v != null) {
+                File f = new File(v);
+                if (f.exists() && f.isDirectory()) {
+                    outputDir = f;
+                }
+            }
         }
     }
 
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 9a8299f..5238086 100644
--- a/core/src/test/java/org/apache/cxf/io/CachedOutputStreamTest.java
+++ b/core/src/test/java/org/apache/cxf/io/CachedOutputStreamTest.java
@@ -116,6 +116,7 @@ public class CachedOutputStreamTest extends CachedStreamTestBase {
             cache.close();
             assertFalse("expects no tmp file", tmpfile.exists());
         } finally {
+            System.clearProperty(CachedConstants.THRESHOLD_SYS_PROP);
             if (old != null) {
                 System.setProperty(CachedConstants.THRESHOLD_SYS_PROP, old);
             }
diff --git a/core/src/test/java/org/apache/cxf/io/CachedStreamTestBase.java b/core/src/test/java/org/apache/cxf/io/CachedStreamTestBase.java
index f71979e..94d49f6 100755
--- a/core/src/test/java/org/apache/cxf/io/CachedStreamTestBase.java
+++ b/core/src/test/java/org/apache/cxf/io/CachedStreamTestBase.java
@@ -27,6 +27,8 @@ import java.io.InputStream;
 import java.io.Reader;
 import java.io.StringWriter;
 import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusFactory;
@@ -206,6 +208,7 @@ public abstract class CachedStreamTestBase extends Assert {
             close(cache);
             assertFalse("expects no tmp file", tmpfile.exists());
         } finally {
+            System.clearProperty(CachedConstants.THRESHOLD_SYS_PROP);
             if (old != null) {
                 System.setProperty(CachedConstants.THRESHOLD_SYS_PROP, old);
             }
@@ -228,6 +231,8 @@ public abstract class CachedStreamTestBase extends Assert {
             EasyMock.expect(b.getProperty(CachedConstants.THRESHOLD_BUS_PROP)).andReturn("4");
             EasyMock.expect(b.getProperty(CachedConstants.MAX_SIZE_BUS_PROP)).andReturn(null);
             EasyMock.expect(b.getProperty(CachedConstants.CIPHER_TRANSFORMATION_BUS_PROP)).andReturn(null);
+            Path tmpDirPath = Files.createTempDirectory("temp-dir");
+            EasyMock.expect(b.getProperty(CachedConstants.OUTPUT_DIRECTORY_BUS_PROP)).andReturn(tmpDirPath.toString());
 
             BusFactory.setThreadDefaultBus(b);
 
@@ -235,6 +240,7 @@ public abstract class CachedStreamTestBase extends Assert {
 
             cache = createCache();
             tmpfile = getTmpFile("Hello World!", cache);
+            assertEquals(tmpfile.getParent(), tmpDirPath.toString());
             assertNotNull("expects a tmp file", tmpfile);
             assertTrue("expects a tmp file", tmpfile.exists());
             close(cache);

-- 
To stop receiving notification emails like this one, please contact
coheigea@apache.org.

Mime
View raw message