You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by co...@apache.org on 2018/04/10 17:10:05 UTC
[cxf] 01/02: Defining constants for caching in a separate file
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
commit 4b84baa96a71431bb471763765c188165f83c1ca
Author: Colm O hEigeartaigh <co...@apache.org>
AuthorDate: Tue Apr 10 16:55:26 2018 +0100
Defining constants for caching in a separate file
---
.../java/org/apache/cxf/io/CachedConstants.java | 71 ++++++++++++++++++++++
.../java/org/apache/cxf/io/CachedOutputStream.java | 21 ++++---
.../main/java/org/apache/cxf/io/CachedWriter.java | 15 ++---
.../org/apache/cxf/io/CachedStreamTestBase.java | 14 ++---
4 files changed, 97 insertions(+), 24 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
new file mode 100644
index 0000000..f8e32b7
--- /dev/null
+++ b/core/src/main/java/org/apache/cxf/io/CachedConstants.java
@@ -0,0 +1,71 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.io;
+
+public final class CachedConstants {
+
+ /**
+ * The directory name for storing the temporary files. None is specified by default.
+ */
+ public static final String OUTPUT_DIRECTORY_SYS_PROP =
+ "org.apache.cxf.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.
+ */
+ public static final String THRESHOLD_SYS_PROP =
+ "org.apache.cxf.io.CachedOutputStream.Threshold";
+
+ /**
+ * The threshold value in bytes to switch from memory to file caching. The default value is 128K for
+ * CachedOutputStream and 64K for CachedWriter.
+ */
+ public static final String THRESHOLD_BUS_PROP =
+ "bus.io.CachedOutputStream.Threshold";
+
+ /**
+ * The data size in bytes to limit the maximum data size to be cached. No max size is set by default.
+ */
+ public static final String MAX_SIZE_SYS_PROP =
+ "org.apache.cxf.io.CachedOutputStream.MaxSize";
+
+ /**
+ * The data size in bytes to limit the maximum data size to be cached. No max size is set by default.
+ */
+ public static final String MAX_SIZE_BUS_PROP =
+ "bus.io.CachedOutputStream.MaxSize";
+
+ /**
+ * The cipher transformation name for encrypting the cached content. None is specified by default.
+ */
+ public static final String CIPHER_TRANSFORMATION_SYS_PROP =
+ "org.apache.cxf.io.CachedOutputStream.CipherTransformation";
+
+ /**
+ * The cipher transformation name for encrypting the cached content. None is specified by default.
+ */
+ public static final String CIPHER_TRANSFORMATION_BUS_PROP =
+ "bus.io.CachedOutputStream.CipherTransformation";
+
+ private CachedConstants() {
+ // complete
+ }
+}
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 0ef7a24..b966ee4 100644
--- a/core/src/main/java/org/apache/cxf/io/CachedOutputStream.java
+++ b/core/src/main/java/org/apache/cxf/io/CachedOutputStream.java
@@ -48,13 +48,14 @@ import org.apache.cxf.helpers.IOUtils;
import org.apache.cxf.helpers.LoadingByteArrayOutputStream;
public class CachedOutputStream extends OutputStream {
+
private static final File DEFAULT_TEMP_DIR;
private static int defaultThreshold;
private static long defaultMaxSize;
private static String defaultCipherTransformation;
- static {
- String s = SystemPropertyAction.getPropertyOrNull("org.apache.cxf.io.CachedOutputStream.OutputDirectory");
+ static {
+ String s = SystemPropertyAction.getPropertyOrNull(CachedConstants.OUTPUT_DIRECTORY_SYS_PROP);
if (s != null) {
File f = new File(s);
if (f.exists() && f.isDirectory()) {
@@ -106,15 +107,15 @@ public class CachedOutputStream extends OutputStream {
private void readBusProperties() {
Bus b = BusFactory.getThreadDefaultBus(false);
if (b != null) {
- String v = getBusProperty(b, "bus.io.CachedOutputStream.Threshold", null);
+ String v = getBusProperty(b, CachedConstants.THRESHOLD_BUS_PROP, null);
if (v != null && threshold == defaultThreshold) {
threshold = Integer.parseInt(v);
}
- v = getBusProperty(b, "bus.io.CachedOutputStream.MaxSize", null);
+ v = getBusProperty(b, CachedConstants.MAX_SIZE_BUS_PROP, null);
if (v != null) {
maxSize = Integer.parseInt(v);
}
- v = getBusProperty(b, "bus.io.CachedOutputStream.CipherTransformation", null);
+ v = getBusProperty(b, CachedConstants.CIPHER_TRANSFORMATION_BUS_PROP, null);
if (v != null) {
cipherTransformation = v;
}
@@ -566,16 +567,15 @@ public class CachedOutputStream extends OutputStream {
public static void setDefaultMaxSize(long l) {
if (l == -1) {
- String s = SystemPropertyAction.getProperty("org.apache.cxf.io.CachedOutputStream.MaxSize",
- "-1");
+ String s = SystemPropertyAction.getProperty(CachedConstants.MAX_SIZE_SYS_PROP, "-1");
l = Long.parseLong(s);
}
defaultMaxSize = l;
}
+
public static void setDefaultThreshold(int i) {
if (i == -1) {
- String s = SystemPropertyAction.getProperty("org.apache.cxf.io.CachedOutputStream.Threshold",
- "-1");
+ String s = SystemPropertyAction.getProperty(CachedConstants.THRESHOLD_SYS_PROP, "-1");
i = Integer.parseInt(s);
if (i <= 0) {
i = 128 * 1024;
@@ -584,9 +584,10 @@ public class CachedOutputStream extends OutputStream {
defaultThreshold = i;
}
+
public static void setDefaultCipherTransformation(String n) {
if (n == null) {
- n = SystemPropertyAction.getPropertyOrNull("org.apache.cxf.io.CachedOutputStream.CipherTransformation");
+ n = SystemPropertyAction.getPropertyOrNull(CachedConstants.CIPHER_TRANSFORMATION_SYS_PROP);
}
defaultCipherTransformation = n;
}
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 9fd4b66..0f697a4 100644
--- a/core/src/main/java/org/apache/cxf/io/CachedWriter.java
+++ b/core/src/main/java/org/apache/cxf/io/CachedWriter.java
@@ -56,7 +56,7 @@ public class CachedWriter extends Writer {
static {
- String s = SystemPropertyAction.getPropertyOrNull("org.apache.cxf.io.CachedOutputStream.OutputDirectory");
+ String s = SystemPropertyAction.getPropertyOrNull(CachedConstants.OUTPUT_DIRECTORY_SYS_PROP);
if (s == null) {
// lookup the deprecated property
s = SystemPropertyAction.getPropertyOrNull("org.apache.cxf.io.CachedWriter.OutputDirectory");
@@ -126,15 +126,15 @@ public class CachedWriter extends Writer {
private void readBusProperties() {
Bus b = BusFactory.getThreadDefaultBus(false);
if (b != null) {
- String v = getBusProperty(b, "bus.io.CachedOutputStream.Threshold", null);
+ String v = getBusProperty(b, CachedConstants.THRESHOLD_BUS_PROP, null);
if (v != null && threshold == defaultThreshold) {
threshold = Integer.parseInt(v);
}
- v = getBusProperty(b, "bus.io.CachedOutputStream.MaxSize", null);
+ v = getBusProperty(b, CachedConstants.MAX_SIZE_BUS_PROP, null);
if (v != null) {
maxSize = Integer.parseInt(v);
}
- v = getBusProperty(b, "bus.io.CachedOutputStream.CipherTransformation", null);
+ v = getBusProperty(b, CachedConstants.CIPHER_TRANSFORMATION_BUS_PROP, null);
if (v != null) {
cipherTransformation = v;
}
@@ -562,7 +562,7 @@ public class CachedWriter extends Writer {
public static void setDefaultMaxSize(long l) {
if (l == -1) {
- String s = System.getProperty("org.apache.cxf.io.CachedOutputStream.MaxSize");
+ String s = System.getProperty(CachedConstants.MAX_SIZE_SYS_PROP);
if (s == null) {
// lookup the deprecated property
s = System.getProperty("org.apache.cxf.io.CachedWriter.MaxSize", "-1");
@@ -571,9 +571,10 @@ public class CachedWriter extends Writer {
}
defaultMaxSize = l;
}
+
public static void setDefaultThreshold(int i) {
if (i == -1) {
- String s = SystemPropertyAction.getProperty("org.apache.cxf.io.CachedOutputStream.Threshold");
+ String s = SystemPropertyAction.getProperty(CachedConstants.THRESHOLD_SYS_PROP);
if (s == null) {
// lookup the deprecated property
s = SystemPropertyAction.getProperty("org.apache.cxf.io.CachedWriter.Threshold", "-1");
@@ -589,7 +590,7 @@ public class CachedWriter extends Writer {
public static void setDefaultCipherTransformation(String n) {
if (n == null) {
- n = SystemPropertyAction.getPropertyOrNull("org.apache.cxf.io.CachedOutputStream.CipherTransformation");
+ n = SystemPropertyAction.getPropertyOrNull(CachedConstants.CIPHER_TRANSFORMATION_SYS_PROP);
}
defaultCipherTransformation = n;
}
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 0bf6a79..f71979e 100755
--- a/core/src/test/java/org/apache/cxf/io/CachedStreamTestBase.java
+++ b/core/src/test/java/org/apache/cxf/io/CachedStreamTestBase.java
@@ -188,16 +188,16 @@ public abstract class CachedStreamTestBase extends Assert {
@Test
public void testUseSysProps() throws Exception {
- String old = System.getProperty("org.apache.cxf.io.CachedOutputStream.Threshold");
+ String old = System.getProperty(CachedConstants.THRESHOLD_SYS_PROP);
try {
- System.clearProperty("org.apache.cxf.io.CachedOutputStream.Threshold");
+ System.clearProperty(CachedConstants.THRESHOLD_SYS_PROP);
reloadDefaultProperties();
Object cache = createCache();
File tmpfile = getTmpFile("Hello World!", cache);
assertNull("expects no tmp file", tmpfile);
close(cache);
- System.setProperty("org.apache.cxf.io.CachedOutputStream.Threshold", "4");
+ System.setProperty(CachedConstants.THRESHOLD_SYS_PROP, "4");
reloadDefaultProperties();
cache = createCache();
tmpfile = getTmpFile("Hello World!", cache);
@@ -207,7 +207,7 @@ public abstract class CachedStreamTestBase extends Assert {
assertFalse("expects no tmp file", tmpfile.exists());
} finally {
if (old != null) {
- System.setProperty("org.apache.cxf.io.CachedOutputStream.Threshold", old);
+ System.setProperty(CachedConstants.THRESHOLD_SYS_PROP, old);
}
}
}
@@ -225,9 +225,9 @@ public abstract class CachedStreamTestBase extends Assert {
IMocksControl control = EasyMock.createControl();
Bus b = control.createMock(Bus.class);
- EasyMock.expect(b.getProperty("bus.io.CachedOutputStream.Threshold")).andReturn("4");
- EasyMock.expect(b.getProperty("bus.io.CachedOutputStream.MaxSize")).andReturn(null);
- EasyMock.expect(b.getProperty("bus.io.CachedOutputStream.CipherTransformation")).andReturn(null);
+ 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);
BusFactory.setThreadDefaultBus(b);
--
To stop receiving notification emails like this one, please contact
coheigea@apache.org.