1
2
3
4
5
6
7
8
9
10
11 package org.mule.transformers.compression;
12
13 import org.mule.umo.transformer.TransformerException;
14 import org.mule.util.compression.GZipCompression;
15
16 import java.io.IOException;
17 import java.io.Serializable;
18
19 import org.apache.commons.lang.SerializationUtils;
20
21
22
23
24
25 public class GZipCompressTransformer extends AbstractCompressionTransformer
26 {
27
28 public GZipCompressTransformer()
29 {
30 super();
31 this.setStrategy(new GZipCompression());
32 this.registerSourceType(Serializable.class);
33 this.registerSourceType(byte[].class);
34 this.setReturnClass(byte[].class);
35 }
36
37 public Object doTransform(Object src, String encoding) throws TransformerException
38 {
39 try
40 {
41 byte[] data = null;
42 if (src instanceof byte[])
43 {
44 data = (byte[]) src;
45 }
46 else
47 {
48 data = SerializationUtils.serialize((Serializable) src);
49 }
50 return this.getStrategy().compressByteArray(data);
51 }
52 catch (IOException ioex)
53 {
54 throw new TransformerException(this, ioex);
55 }
56 }
57
58 }