incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1545544 - in /sling/trunk/bundles/servlets/get/src: main/java/org/apache/sling/servlets/get/impl/helpers/StreamRendererServlet.java test/java/org/apache/sling/servlets/get/impl/helpers/StreamRendererServletTest.java
Date Tue, 26 Nov 2013 05:45:27 GMT
Author: bdelacretaz
Date: Tue Nov 26 05:45:27 2013
New Revision: 1545544

URL: http://svn.apache.org/r1545544
Log:
SLING-3256 - StreamRendererServlet was wrong when read returns < len - thanks Tobias Bocanegra
and Alex Klimetschek for the report and patch!

Modified:
    sling/trunk/bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/helpers/StreamRendererServlet.java
    sling/trunk/bundles/servlets/get/src/test/java/org/apache/sling/servlets/get/impl/helpers/StreamRendererServletTest.java

Modified: sling/trunk/bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/helpers/StreamRendererServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/helpers/StreamRendererServlet.java?rev=1545544&r1=1545543&r2=1545544&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/helpers/StreamRendererServlet.java
(original)
+++ sling/trunk/bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/helpers/StreamRendererServlet.java
Tue Nov 26 05:45:27 2013
@@ -545,7 +545,7 @@ public class StreamRendererServlet exten
             int read = istream.read(buffer, 0, len);
             if (read != -1) {
                 position += read;
-                ostream.write(buffer, 0, len);
+                ostream.write(buffer, 0, read);
             } else {
                 break;
             }

Modified: sling/trunk/bundles/servlets/get/src/test/java/org/apache/sling/servlets/get/impl/helpers/StreamRendererServletTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/get/src/test/java/org/apache/sling/servlets/get/impl/helpers/StreamRendererServletTest.java?rev=1545544&r1=1545543&r2=1545544&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/get/src/test/java/org/apache/sling/servlets/get/impl/helpers/StreamRendererServletTest.java
(original)
+++ sling/trunk/bundles/servlets/get/src/test/java/org/apache/sling/servlets/get/impl/helpers/StreamRendererServletTest.java
Tue Nov 26 05:45:27 2013
@@ -96,13 +96,24 @@ public class StreamRendererServletTest {
                 return 0;
             }
         }), a, b);
+        // with an input stream that does not return everything in read()
+        assertCopyRange(expected, new ByteArrayInputStream(expected) {
+            @Override
+            public synchronized int read(byte[] b, int off, int len) {
+                // allow maximum of 10
+                if (len > 10) {
+                    len = 10;
+                }
+                return super.read(b, off, len);
+            }
+        }, a, b);
     }
 
     private void assertCopyRange(
             byte[] expected, InputStream input, int a, int b) throws IOException {
         ByteArrayOutputStream output = new ByteArrayOutputStream();
-        StreamRendererServlet.staticCopyRange(
-                new ByteArrayInputStream(expected), output, a, b);
+
+        StreamRendererServlet.staticCopyRange(input, output, a, b);
 
         byte[] actual = output.toByteArray();
         assertEquals(b - a, actual.length);



Mime
View raw message