KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: GZipUncompressTransformer.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
19 /**
20  * <code>GZipCompressTransformer</code> TODO
21  *
22  * @author <a HREF="mailto:ross.mason@symphonysoft.com">Ross Mason</a>
23  * @version $Revision: 3798 $
24  */

25 public class GZipUncompressTransformer extends GZipCompressTransformer
26 {
27     /**
28      * Serial version
29      */

30     private static final long serialVersionUID = -861180612454404077L;
31
32     public GZipUncompressTransformer()
33     {
34         super();
35         this.setStrategy(new GZipCompression());
36         this.registerSourceType(byte[].class);
37         this.setReturnClass(byte[].class);
38
39     }
40
41     public Object JavaDoc doTransform(Object JavaDoc src, String JavaDoc encoding) throws TransformerException
42     {
43         byte[] buffer = null;
44
45         try
46         {
47             buffer = getStrategy().uncompressByteArray((byte[])src);
48         }
49         catch (IOException JavaDoc e)
50         {
51             logger.error("Failed to uncompress message:", e);
52             throw new TransformerException(this, e);
53         }
54
55         if (!getReturnClass().equals(byte[].class))
56         {
57             return SerializationUtils.deserialize(buffer);
58         }
59
60         return buffer;
61     }
62
63 }
64
Popular Tags