1 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 ; 18 import java.io.Serializable ; 19 20 27 public class GZipCompressTransformer extends AbstractCompressionTransformer 28 { 29 32 private static final long serialVersionUID = 5841897266012659925L; 33 34 public GZipCompressTransformer() 35 { 36 super(); 37 this.setStrategy(new GZipCompression()); 38 this.registerSourceType(Serializable .class); 39 this.registerSourceType(byte[].class); 40 this.setReturnClass(byte[].class); 41 } 42 43 public Object doTransform(Object src, String 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 )src); 55 } 56 return this.getStrategy().compressByteArray(data); 57 } 58 catch (IOException ioex) 59 { 60 throw new TransformerException(this, ioex); 61 } 62 } 63 64 } 65 | Popular Tags |