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 | 44 | super(); |
31 | 44 | this.setStrategy(new GZipCompression()); |
32 | 48 | this.registerSourceType(Serializable.class); |
33 | 44 | this.registerSourceType(byte[].class); |
34 | 44 | this.setReturnClass(byte[].class); |
35 | 44 | } |
36 | |
|
37 | |
public Object doTransform(Object src, String encoding) throws TransformerException |
38 | |
{ |
39 | |
try |
40 | |
{ |
41 | 10 | byte[] data = null; |
42 | 10 | if (src instanceof byte[]) |
43 | |
{ |
44 | 4 | data = (byte[]) src; |
45 | |
} |
46 | |
else |
47 | |
{ |
48 | 6 | data = SerializationUtils.serialize((Serializable) src); |
49 | |
} |
50 | 10 | return this.getStrategy().compressByteArray(data); |
51 | |
} |
52 | 0 | catch (IOException ioex) |
53 | |
{ |
54 | 0 | throw new TransformerException(this, ioex); |
55 | |
} |
56 | |
} |
57 | |
|
58 | |
} |