FileDocCategorySizeDatePackage
GzipInterceptor.javaAPI DocApache Tomcat 6.0.143705Fri Jul 20 04:20:36 BST 2007org.apache.catalina.tribes.group.interceptors

GzipInterceptor

public class GzipInterceptor extends org.apache.catalina.tribes.group.ChannelInterceptorBase
author
Filip Hanik
version
1.0

Fields Summary
public static final int
DEFAULT_BUFFER_SIZE
Constructors Summary
Methods Summary
public static byte[]compress(byte[] data)

        ByteArrayOutputStream bout = new ByteArrayOutputStream();
        GZIPOutputStream gout = new GZIPOutputStream(bout);
        gout.write(data);
        gout.flush();
        gout.close();
        return bout.toByteArray();
    
public static byte[]decompress(byte[] data)

todo
Fix to create an automatically growing buffer.
param
data byte[]
return
byte[]
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 voidmain(java.lang.String[] arg)

        byte[] data = new byte[1024];
        Arrays.fill(data,(byte)1);
        byte[] compress = compress(data);
        byte[] decompress = decompress(compress);
        System.out.println("Debug test");
        
    
public voidmessageReceived(org.apache.catalina.tribes.ChannelMessage msg)

        try {
            byte[] data = decompress(msg.getMessage().getBytes());
            msg.getMessage().trim(msg.getMessage().getLength());
            msg.getMessage().append(data,0,data.length);
            getPrevious().messageReceived(msg);
        } catch ( IOException x ) {
            log.error("Unable to decompress byte contents",x);
        }
    
public voidsendMessage(org.apache.catalina.tribes.Member[] destination, org.apache.catalina.tribes.ChannelMessage msg, org.apache.catalina.tribes.group.InterceptorPayload payload)

    
              
        try {
            byte[] data = compress(msg.getMessage().getBytes());
            msg.getMessage().trim(msg.getMessage().getLength());
            msg.getMessage().append(data,0,data.length);
            getNext().sendMessage(destination, msg, payload);
        } catch ( IOException x ) {
            log.error("Unable to compress byte contents");
            throw new ChannelException(x);
        }