tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Konstantin Kolinko <knst.koli...@gmail.com>
Subject Re: svn commit: r1143134 - in /tomcat/trunk: java/org/apache/catalina/tribes/group/interceptors/GzipInterceptor.java test/org/apache/catalina/tribes/group/interceptors/TestGzipInterceptor.java
Date Tue, 05 Jul 2011 17:23:33 GMT
2011/7/5  <markt@apache.org>:
> 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
>

>     public static byte[] decompress(byte[] data) throws IOException {
> +        ByteArrayOutputStream bout = new ByteArrayOutputStream();

The above has initial size of 32 bytes.
It looks too short but I do not know what typical sizes are in tribes here.

DEFAULT_BUFFER_SIZE will be 2Kb.


>         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;

Just
int  length = gin.read(tmp);
will save an iteration.

> +        while (length > -1) {
> +            bout.write(tmp, 0, length);
> +            length = gin.read(tmp);
> +        }
> +        return bout.toByteArray();
>     }
>  }

Best regards,
Konstantin Kolinko

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message