cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jo...@apache.org
Subject svn commit: r651169 - in /cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src: changes/ main/java/org/apache/cocoon/caching/ test/java/org/apache/cocoon/caching/
Date Thu, 24 Apr 2008 06:37:29 GMT
Author: joerg
Date: Wed Apr 23 23:37:20 2008
New Revision: 651169

URL: http://svn.apache.org/viewvc?rev=651169&view=rev
Log:
COCOON-2192: Fix CachingOutputStream not caching all content or leading to ArrayIndexOutOfBoundsException
when using write(byte[], int, int).

Added:
    cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/test/java/org/apache/cocoon/caching/
    cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/test/java/org/apache/cocoon/caching/CachingOutputStreamTestCase.java
Modified:
    cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/changes/changes.xml
    cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/caching/CachingOutputStream.java

Modified: cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/changes/changes.xml?rev=651169&r1=651168&r2=651169&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/changes/changes.xml (original)
+++ cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/changes/changes.xml Wed Apr
23 23:37:20 2008
@@ -24,7 +24,11 @@
   -->
 <document>
   <body>
-    <release version="1.0.1" date="TBA" description="unreleased">
+    <release version="1.0.1" date="TBD" description="unreleased">
+      <action dev="joerg" type="fix" fixes-bug="COCOON-2192" due-to="Steven Dolg" due-to-email="steven.dolg@indoqa.com">
+        Fix CachingOutputStream not caching all content or leading to ArrayIndexOutOfBoundsException
when using
+        write(byte[], int, int).
+      </action>
       <action dev="joerg" type="update" fixes-bug="COCOON-2168">
         Set the default output buffer size of the pipeline to 1,048,576 (1 MB) rather than
-1 (complete buffering) to
         avoid potential OutOfMemoryErrors on too large output.

Modified: cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/caching/CachingOutputStream.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/caching/CachingOutputStream.java?rev=651169&r1=651168&r2=651169&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/caching/CachingOutputStream.java
(original)
+++ cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/caching/CachingOutputStream.java
Wed Apr 23 23:37:20 2008
@@ -53,7 +53,7 @@
         this.receiver.write(b);
         int newcount = this.bufCount + 1;
         if (newcount > this.buf.length) {
-            byte newbuf[] = new byte[Math.max(this.buf.length << 1, newcount)];
+            byte newbuf[] = new byte[this.buf.length << 1];
             System.arraycopy(this.buf, 0, newbuf, 0, this.bufCount);
             this.buf = newbuf;
         }
@@ -68,7 +68,7 @@
     public void write(byte b[], int off, int len) throws IOException {
         this.receiver.write(b, off, len);
         if (len == 0) return;
-        int newcount = this.bufCount + (len-off);
+        int newcount = this.bufCount + len;
         if (newcount > this.buf.length) {
             byte newbuf[] = new byte[Math.max(this.buf.length << 1, newcount)];
             System.arraycopy(this.buf, 0, newbuf, 0, this.bufCount);

Added: cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/test/java/org/apache/cocoon/caching/CachingOutputStreamTestCase.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/test/java/org/apache/cocoon/caching/CachingOutputStreamTestCase.java?rev=651169&view=auto
==============================================================================
--- cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/test/java/org/apache/cocoon/caching/CachingOutputStreamTestCase.java
(added)
+++ cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/test/java/org/apache/cocoon/caching/CachingOutputStreamTestCase.java
Wed Apr 23 23:37:20 2008
@@ -0,0 +1,118 @@
+/*
+ * 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.cocoon.caching;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Random;
+
+import junit.framework.TestCase;
+
+public class CachingOutputStreamTestCase extends TestCase {
+
+    public void testWriteInt() throws IOException {
+        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+        CachingOutputStream cachingOutputStream = new CachingOutputStream(byteArrayOutputStream);
+
+        for (int i = 0; i < 1000; i++) {
+            cachingOutputStream.write(i);
+        }
+
+        // the content in the original destination
+        byte[] content = byteArrayOutputStream.toByteArray();
+        // the content collected in the CachingOutputStream
+        byte[] cachedContent = cachingOutputStream.getContent();
+
+        assertEquals("Length of cached content is wrong:", content.length, cachedContent.length);
+        assertTrue("Cached content differs", Arrays.equals(content, cachedContent));
+        
+        // Test to exceed CachingOutputStream's buffer of 1024.
+        for (int i = 0; i < 1000; i++) {
+            cachingOutputStream.write(i);
+        }
+
+        // the content in the original destination
+        content = byteArrayOutputStream.toByteArray();
+        // the content collected in the CachingOutputStream
+        cachedContent = cachingOutputStream.getContent();
+
+        assertEquals("Length of cached content is wrong:", content.length, cachedContent.length);
+        assertTrue("Cached content differs", Arrays.equals(content, cachedContent));
+    }
+
+    public void testWriteByteArray() throws IOException {
+        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+        CachingOutputStream cachingOutputStream = new CachingOutputStream(byteArrayOutputStream);
+
+        byte[] data = new byte[1000];
+        new Random().nextBytes(data);
+        cachingOutputStream.write(data);
+
+        // the content in the original destination
+        byte[] content = byteArrayOutputStream.toByteArray();
+        // the content collected in the CachingOutputStream
+        byte[] cachedContent = cachingOutputStream.getContent();
+
+        assertEquals("Length of cached content is wrong:", content.length, cachedContent.length);
+        assertTrue("Cached content differs", Arrays.equals(data, cachedContent));
+        assertTrue("Cached content differs", Arrays.equals(content, cachedContent));
+
+        // Test to exceed CachingOutputStream's buffer of 1024.
+        cachingOutputStream.write(data);
+
+        // the content in the original destination
+        content = byteArrayOutputStream.toByteArray();
+        // the content collected in the CachingOutputStream
+        cachedContent = cachingOutputStream.getContent();
+
+        assertEquals("Length of cached content is wrong:", content.length, cachedContent.length);
+        assertTrue("Cached content differs", Arrays.equals(content, cachedContent));
+    }
+
+    public void testWriteByteArrayPart() throws IOException {
+        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+        CachingOutputStream cachingOutputStream = new CachingOutputStream(byteArrayOutputStream);
+
+        byte[] data = new byte[1000];
+        new Random().nextBytes(data);
+        for (int i = 0; i < 10; i++) {
+            cachingOutputStream.write(data, i * 100, 100);
+        }
+
+        // the content in the original destination
+        byte[] content = byteArrayOutputStream.toByteArray();
+        // the content collected in the CachingOutputStream
+        byte[] cachedContent = cachingOutputStream.getContent();
+
+        assertEquals("Length of cached content is wrong:", content.length, cachedContent.length);
+        assertTrue("Cached content differs", Arrays.equals(data, cachedContent));
+        assertTrue("Cached content differs", Arrays.equals(content, cachedContent));
+
+        // Test to exceed CachingOutputStream's buffer of 1024.
+        cachingOutputStream.write(data, 200, 100);
+
+        // the content in the original destination
+        content = byteArrayOutputStream.toByteArray();
+        // the content collected in the CachingOutputStream
+        cachedContent = cachingOutputStream.getContent();
+
+        assertEquals("Length of cached content is wrong:", content.length, cachedContent.length);
+        assertTrue("Cached content differs", Arrays.equals(content, cachedContent));
+    }
+
+}



Mime
View raw message