Author: markt
Date: Tue Jul 5 16:45:38 2011
New Revision: 1143134
URL: http://svn.apache.org/viewvc?rev=1143134&view=rev
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=51475
Handle messages larger than the buffer size. Expand test cases to cover this.
Based on a patch by Christian Stöber.
Modified:
tomcat/trunk/java/org/apache/catalina/tribes/group/interceptors/GzipInterceptor.java
tomcat/trunk/test/org/apache/catalina/tribes/group/interceptors/TestGzipInterceptor.java
Modified:
tomcat/trunk/java/org/apache/catalina/tribes/group/interceptors/GzipInterceptor.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/tribes/group/interceptors/GzipInterceptor.java?rev=1143134&r1=1143133&r2=1143134&view=diff
==============================================================================
---
tomcat/trunk/java/org/apache/catalina/tribes/group/interceptors/GzipInterceptor.java
(original)
+++
tomcat/trunk/java/org/apache/catalina/tribes/group/interceptors/GzipInterceptor.java
Tue Jul 5 16:45:38 2011
@@ -77,18 +77,20 @@ public class GzipInterceptor extends Cha
}
/**
- * TODO Fix to create an automatically growing buffer.
- * @param data byte[]
- * @return byte[]
+ * @param data Data to decompress
+ * @return Decompressed data
* @throws IOException
*/
public static byte[] decompress(byte[] data) throws IOException {
+ ByteArrayOutputStream bout = new ByteArrayOutputStream();
ByteArrayInputStream bin = new ByteArrayInputStream(data);
GZIPInputStream gin = new GZIPInputStream(bin);
byte[] tmp = new byte[DEFAULT_BUFFER_SIZE];
- int length = gin.read(tmp);
- byte[] result = new byte[length];
- System.arraycopy(tmp,0,result,0,length);
- return result;
+ int length = 0;
+ while (length > -1) {
+ bout.write(tmp, 0, length);
+ length = gin.read(tmp);
+ }
+ return bout.toByteArray();
}
}
Modified:
tomcat/trunk/test/org/apache/catalina/tribes/group/interceptors/TestGzipInterceptor.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/tribes/group/interceptors/TestGzipInterceptor.java?rev=1143134&r1=1143133&r2=1143134&view=diff
==============================================================================
---
tomcat/trunk/test/org/apache/catalina/tribes/group/interceptors/TestGzipInterceptor.java
(original)
+++
tomcat/trunk/test/org/apache/catalina/tribes/group/interceptors/TestGzipInterceptor.java
Tue Jul 5 16:45:38 2011
@@ -22,9 +22,37 @@ import junit.framework.TestCase;
public class TestGzipInterceptor extends TestCase {
- public void testBasic() throws Exception {
- byte[] data = new byte[1024];
- Arrays.fill(data,(byte)1);
+ public void testSmallerThanBufferSize() throws Exception {
+ doCompressDecompress(GzipInterceptor.DEFAULT_BUFFER_SIZE / 2);
+ }
+
+ public void testJustSmallerThanBufferSize() throws Exception {
+ doCompressDecompress(GzipInterceptor.DEFAULT_BUFFER_SIZE -1);
+ }
+
+ public void testExactBufferSize() throws Exception {
+ doCompressDecompress(GzipInterceptor.DEFAULT_BUFFER_SIZE);
+ }
+
+ public void testJustLargerThanBufferSize() throws Exception {
+ doCompressDecompress(GzipInterceptor.DEFAULT_BUFFER_SIZE + 1);
+ }
+
+ public void testFactor2BufferSize() throws Exception {
+ doCompressDecompress(GzipInterceptor.DEFAULT_BUFFER_SIZE * 2);
+ }
+
+ public void testFactor4BufferSize() throws Exception {
+ doCompressDecompress(GzipInterceptor.DEFAULT_BUFFER_SIZE * 4);
+ }
+
+ public void testMuchLargerThanBufferSize() throws Exception {
+ doCompressDecompress(GzipInterceptor.DEFAULT_BUFFER_SIZE * 10 + 1000);
+ }
+
+ private void doCompressDecompress(int size) throws Exception {
+ byte[] data = new byte[size];
+ Arrays.fill(data, (byte)1);
byte[] compress = GzipInterceptor.compress(data);
byte[] result = GzipInterceptor.decompress(compress);
assertTrue(Arrays.equals(data, result));
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]