You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2009/07/26 14:21:19 UTC
svn commit: r797920 - in /camel/branches/camel-1.x/camel-core/src:
main/java/org/apache/camel/converter/stream/CachedOutputStream.java
test/java/org/apache/camel/converter/stream/CachedOutputStreamTest.java
Author: davsclaus
Date: Sun Jul 26 12:21:19 2009
New Revision: 797920
URL: http://svn.apache.org/viewvc?rev=797920&view=rev
Log:
CAMEL-1849: disk based stream cache can be disabled using a threshold of 0 or negative.
Modified:
camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/converter/stream/CachedOutputStream.java
camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/converter/stream/CachedOutputStreamTest.java
Modified: camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/converter/stream/CachedOutputStream.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/converter/stream/CachedOutputStream.java?rev=797920&r1=797919&r2=797920&view=diff
==============================================================================
--- camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/converter/stream/CachedOutputStream.java (original)
+++ camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/converter/stream/CachedOutputStream.java Sun Jul 26 12:21:19 2009
@@ -71,10 +71,7 @@
this();
String value = properties.get(THRESHOLD);
if (value != null) {
- int i = Integer.parseInt(value);
- if (i > 0) {
- threshold = i;
- }
+ threshold = Integer.parseInt(value);
}
value = properties.get(TEMP_DIR);
if (value != null) {
@@ -314,7 +311,7 @@
if (!outputLocked) {
onWrite();
this.totalLength += len;
- if (inmem && totalLength > threshold && currentStream instanceof ByteArrayOutputStream) {
+ if (threshold > 0 && inmem && totalLength > threshold && currentStream instanceof ByteArrayOutputStream) {
createFileOutputStream();
}
currentStream.write(b, off, len);
@@ -325,7 +322,7 @@
if (!outputLocked) {
onWrite();
this.totalLength += b.length;
- if (inmem && totalLength > threshold && currentStream instanceof ByteArrayOutputStream) {
+ if (threshold > 0 && inmem && totalLength > threshold && currentStream instanceof ByteArrayOutputStream) {
createFileOutputStream();
}
currentStream.write(b);
@@ -336,7 +333,7 @@
if (!outputLocked) {
onWrite();
this.totalLength++;
- if (inmem && totalLength > threshold && currentStream instanceof ByteArrayOutputStream) {
+ if (threshold > 0 && inmem && totalLength > threshold && currentStream instanceof ByteArrayOutputStream) {
createFileOutputStream();
}
currentStream.write(b);
Modified: camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/converter/stream/CachedOutputStreamTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/converter/stream/CachedOutputStreamTest.java?rev=797920&r1=797919&r2=797920&view=diff
==============================================================================
--- camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/converter/stream/CachedOutputStreamTest.java (original)
+++ camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/converter/stream/CachedOutputStreamTest.java Sun Jul 26 12:21:19 2009
@@ -68,7 +68,7 @@
cos.setOutputDir(file);
cos.write(TEST_STRING.getBytes("UTF-8"));
String[] files = file.list();
- assertEquals("we should have a temp file", files.length, 1);
+ assertEquals("we should have a temp file", 1, files.length);
assertTrue("The file name should start with cos" , files[0].startsWith("cos"));
StreamCache cache = cos.getStreamCache();
@@ -84,17 +84,16 @@
// do nothing
}
files = file.list();
- assertEquals("we should have no temp file", files.length, 0);
+ assertEquals("we should have no temp file", 0, files.length);
}
public void testCacheStreamToFileAndNotCloseStream() throws IOException {
-
CachedOutputStream cos = new CachedOutputStream(16);
cos.setOutputDir(file);
cos.write(TEST_STRING.getBytes("UTF-8"));
String[] files = file.list();
- assertEquals("we should have a temp file", files.length, 1);
+ assertEquals("we should have a temp file", 1, files.length);
assertTrue("The file name should start with cos" , files[0].startsWith("cos"));
StreamCache cache = cos.getStreamCache();
@@ -107,7 +106,7 @@
((InputStream)cache).close();
files = file.list();
- assertEquals("we should have no temp file", files.length, 0);
+ assertEquals("we should have no temp file", 0, files.length);
}
public void testCacheStreamToMemory() throws IOException {
@@ -115,7 +114,19 @@
cos.setOutputDir(file);
cos.write(TEST_STRING.getBytes("UTF-8"));
String[] files = file.list();
- assertEquals("we should have no temp file", files.length, 0);
+ assertEquals("we should have no temp file", 0, files.length);
+ StreamCache cache = cos.getStreamCache();
+ assertTrue("Should get the InputStreamCache", cache instanceof InputStreamCache);
+ String temp = IOConverter.toString((InputStream)cache);
+ assertEquals("Cached a wrong file", temp, TEST_STRING);
+ }
+
+ public void testCacheStreamToMemoryAsDiskIsDisabled() throws IOException {
+ CachedOutputStream cos = new CachedOutputStream(-1);
+ cos.setOutputDir(file);
+ cos.write(TEST_STRING.getBytes("UTF-8"));
+ String[] files = file.list();
+ assertEquals("we should have no temp file", 0, files.length);
StreamCache cache = cos.getStreamCache();
assertTrue("Should get the InputStreamCache", cache instanceof InputStreamCache);
String temp = IOConverter.toString((InputStream)cache);