Author: fmui
Date: Wed Apr 8 07:35:02 2015
New Revision: 1672015
URL: http://svn.apache.org/r1672015
Log:
Server: allow the memory threshold to be set to 0 (=temp data should always be
stored on disk)
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/ThresholdOutputStream.java
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/test/java/org/apache/chemistry/opencmis/server/impl/ThresholdOutputStreamTest.java
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/ThresholdOutputStream.java
URL:
http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/ThresholdOutputStream.java?rev=1672015&r1=1672014&r2=1672015&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/ThresholdOutputStream.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/ThresholdOutputStream.java
Wed Apr 8 07:35:02 2015
@@ -64,6 +64,7 @@ public class ThresholdOutputStream exten
private final File tempDir;
private final int memoryThreshold;
+ private final int initSize;
private final long maxContentSize;
private final boolean encrypt;
@@ -124,6 +125,7 @@ public class ThresholdOutputStream exten
throw new IllegalArgumentException("Negative initial size: " +
initSize);
}
+ this.initSize = initSize;
this.tempDir = tempDir;
this.memoryThreshold = (memoryThreshold < 0 ? DEFAULT_THRESHOLD :
memoryThreshold);
this.maxContentSize = maxContentSize;
@@ -144,7 +146,14 @@ public class ThresholdOutputStream exten
tmpStream.write(buf, 0, bufSize);
if (buf.length != memoryThreshold) {
- buf = new byte[memoryThreshold];
+ if (memoryThreshold >= initSize) {
+ buf = new byte[memoryThreshold];
+ } else if (buf.length != initSize) {
+ buf = new byte[initSize];
+ }
+ }
+ if (buf.length < nextBufferSize) {
+ buf = new byte[nextBufferSize];
}
bufSize = 0;
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/test/java/org/apache/chemistry/opencmis/server/impl/ThresholdOutputStreamTest.java
URL:
http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/test/java/org/apache/chemistry/opencmis/server/impl/ThresholdOutputStreamTest.java?rev=1672015&r1=1672014&r2=1672015&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/test/java/org/apache/chemistry/opencmis/server/impl/ThresholdOutputStreamTest.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/test/java/org/apache/chemistry/opencmis/server/impl/ThresholdOutputStreamTest.java
Wed Apr 8 07:35:02 2015
@@ -207,6 +207,30 @@ public class ThresholdOutputStreamTest {
}
}
+ @Test
+ public void testNoThreshold() throws Exception {
+ int size = 128 * 1024;
+
+ TempStoreOutputStreamFactory streamFactory =
TempStoreOutputStreamFactory.newInstance(null, 0, size * 2, false);
+
+ TempStoreOutputStream tempStream = streamFactory.newOutputStream();
+ assertTrue(tempStream instanceof ThresholdOutputStream);
+
+ ThresholdOutputStream tos = (ThresholdOutputStream) tempStream;
+
+ byte[] bytes = new byte[size];
+ tos.write(bytes);
+ tos.close();
+
+ ThresholdInputStream tis = (ThresholdInputStream) tos.getInputStream();
+ assertFalse(tis.isInMemory());
+
+ File tempFile = tis.getTemporaryFile();
+ assertEquals(size, tempFile.length());
+
+ tis.close();
+ }
+
private byte[] getBytesFromArray(byte[] buffer, int len) {
byte[] result = new byte[len];