KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > transformers > compression > GZipCompressTransformer


1 /*
2  * $Id: GZipCompressTransformer.java 3798 2006-11-04 04:07:14Z aperepel $
3  * --------------------------------------------------------------------------------------
4  * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
5  *
6  * The software in this package is published under the terms of the MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

10
11 package org.mule.transformers.compression;
12
13 import org.apache.commons.lang.SerializationUtils;
14 import org.mule.umo.transformer.TransformerException;
15 import org.mule.util.compression.GZipCompression;
16
17 import java.io.IOException JavaDoc;
18 import java.io.Serializable JavaDoc;
19
20 /**
21  * <code>GZipCompressTransformer</code> is a transformer compressing objects into
22  * byte arrays
23  *
24  * @author <a HREF="mailto:ross.mason@symphonysoft.com">Ross Mason</a>
25  * @version $Revision: 3798 $
26  */

27 public class GZipCompressTransformer extends AbstractCompressionTransformer
28 {
29     /**
30      * Serial version
31      */

32     private static final long serialVersionUID = 5841897266012659925L;
33
34     public GZipCompressTransformer()
35     {
36         super();
37         this.setStrategy(new GZipCompression());
38         this.registerSourceType(Serializable JavaDoc.class);
39         this.registerSourceType(byte[].class);
40         this.setReturnClass(byte[].class);
41     }
42
43     public Object JavaDoc doTransform(Object JavaDoc src, String JavaDoc encoding) throws TransformerException
44     {
45         try
46         {
47             byte[] data = null;
48             if (src instanceof byte[])
49             {
50                 data = (byte[])src;
51             }
52             else
53             {
54                 data = SerializationUtils.serialize((Serializable JavaDoc)src);
55             }
56             return this.getStrategy().compressByteArray(data);
57         }
58         catch (IOException JavaDoc ioex)
59         {
60             throw new TransformerException(this, ioex);
61         }
62     }
63
64 }
65
Popular Tags