ASF Bugzilla – Attachment 27256 Details for
Bug 51475
GzipInterceptor#decompress is not completly implemented
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
Patch file for GzipInterceptor, TestGzipInterceptor and TribesTestSuite
patch.txt (text/plain), 5.42 KB, created by
Christian Stöber
on 2011-07-05 12:08:55 UTC
(
hide
)
Description:
Patch file for GzipInterceptor, TestGzipInterceptor and TribesTestSuite
Filename:
MIME Type:
Creator:
Christian Stöber
Created:
2011-07-05 12:08:55 UTC
Size:
5.42 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P Tomcat 6.0.x >Index: test/org/apache/catalina/tribes/test/TribesTestSuite.java >=================================================================== >--- test/org/apache/catalina/tribes/test/TribesTestSuite.java (revision 1142976) >+++ test/org/apache/catalina/tribes/test/TribesTestSuite.java (working copy) >@@ -36,6 +36,7 @@ > suite.addTestSuite(org.apache.catalina.tribes.test.membership.TestTcpFailureDetector.class); > suite.addTestSuite(org.apache.catalina.tribes.test.channel.TestDataIntegrity.class); > suite.addTestSuite(org.apache.catalina.tribes.test.interceptors.TestOrderInterceptor.class); >+ suite.addTestSuite(org.apache.catalina.tribes.test.interceptors.TestGzipInterceptor.class); > return suite; > } > } >Index: java/org/apache/catalina/tribes/group/interceptors/GzipInterceptor.java >=================================================================== >--- java/org/apache/catalina/tribes/group/interceptors/GzipInterceptor.java (revision 1142976) >+++ java/org/apache/catalina/tribes/group/interceptors/GzipInterceptor.java (working copy) >@@ -5,9 +5,9 @@ > * 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. >@@ -19,7 +19,6 @@ > import java.io.ByteArrayInputStream; > import java.io.ByteArrayOutputStream; > import java.io.IOException; >-import java.util.Arrays; > import java.util.zip.GZIPInputStream; > import java.util.zip.GZIPOutputStream; > >@@ -39,7 +38,8 @@ > */ > public class GzipInterceptor extends ChannelInterceptorBase { > public static final int DEFAULT_BUFFER_SIZE = 2048; >- >+ >+ @Override > public void sendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload payload) throws ChannelException { > try { > byte[] data = compress(msg.getMessage().getBytes()); >@@ -52,6 +52,7 @@ > } > } > >+ @Override > public void messageReceived(ChannelMessage msg) { > try { > byte[] data = decompress(msg.getMessage().getBytes()); >@@ -62,7 +63,12 @@ > log.error("Unable to decompress byte contents",x); > } > } >- >+ >+ /** >+ * @param data Uncompressed data >+ * @return Compressed data >+ * @throws IOException >+ */ > public static byte[] compress(byte[] data) throws IOException { > ByteArrayOutputStream bout = new ByteArrayOutputStream(); > GZIPOutputStream gout = new GZIPOutputStream(bout); >@@ -71,30 +77,26 @@ > gout.close(); > return bout.toByteArray(); > } >- >+ > /** >- * @todo Fix to create an automatically growing buffer. >- * @param data byte[] >- * @return byte[] >+ * @param data Compressed data >+ * @return Decompressed data > * @throws IOException > */ > public static byte[] decompress(byte[] data) throws IOException { >- 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; >- } >- >- public static void main(String[] arg) throws Exception { >- byte[] data = new byte[1024]; >- Arrays.fill(data,(byte)1); >- byte[] compress = compress(data); >- byte[] decompress = decompress(compress); >- System.out.println("Debug test"); >- >+ ByteArrayOutputStream bout = new ByteArrayOutputStream(); >+ ByteArrayInputStream bin = new ByteArrayInputStream(data); >+ GZIPInputStream gin = new GZIPInputStream(bin); >+ >+ byte[] buf = new byte[DEFAULT_BUFFER_SIZE]; >+ while (true) { >+ int length = gin.read(buf); >+ if (length == -1) { >+ break; >+ } >+ bout.write(buf, 0, length); >+ } >+ >+ return bout.toByteArray(); > } >- > } >Index: test/org/apache/catalina/tribes/test/interceptors/TestGzipInterceptor.java >=================================================================== >--- test/org/apache/catalina/tribes/test/interceptors/TestGzipInterceptor.java (revision 0) >+++ test/org/apache/catalina/tribes/test/interceptors/TestGzipInterceptor.java (revision 0) >@@ -0,0 +1,35 @@ >+package org.apache.catalina.tribes.test.interceptors; >+ >+import java.util.Arrays; >+ >+import junit.framework.TestCase; >+ >+import org.apache.catalina.tribes.group.interceptors.GzipInterceptor; >+ >+public class TestGzipInterceptor extends TestCase { >+ >+ public final void testCompressAndDecompress() { >+ test(1024); >+ test(2048); >+ test(4096); >+ test(8192); >+ } >+ >+ private static void test(int size) { >+ try >+ { >+ byte[] data = new byte[size]; >+ Arrays.fill(data, (byte) 1); >+ >+ byte[] compressed = GzipInterceptor.compress(data); >+ System.out.println(compressed.length); >+ byte[] decompressed = GzipInterceptor.decompress(compressed); >+ >+ assertTrue("Data and decompressed data should be equal.", Arrays.equals(data, decompressed)); >+ } >+ catch (Exception e) >+ { >+ fail(e.getMessage()); >+ } >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 51475
:
27254
| 27256