Coverage Report - org.mule.transformers.compression.GZipCompressTransformer
 
Classes in this File Line Coverage Branch Coverage Complexity
GZipCompressTransformer
0%
0/13
0%
0/4
3
 
 1  
 /*
 2  
  * $Id: GZipCompressTransformer.java 7976 2007-08-21 14:26:13Z dirk.olmes $
 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 CPAL v1.0
 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.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  
  * <code>GZipCompressTransformer</code> is a transformer compressing objects into
 23  
  * byte arrays.
 24  
  */
 25  
 public class GZipCompressTransformer extends AbstractCompressionTransformer
 26  
 {
 27  
 
 28  
     public GZipCompressTransformer()
 29  
     {
 30  0
         super();
 31  0
         this.setStrategy(new GZipCompression());
 32  0
         this.registerSourceType(Serializable.class);
 33  0
         this.registerSourceType(byte[].class);
 34  0
         this.setReturnClass(byte[].class);
 35  0
     }
 36  
 
 37  
     public Object doTransform(Object src, String encoding) throws TransformerException
 38  
     {
 39  
         try
 40  
         {
 41  0
             byte[] data = null;
 42  0
             if (src instanceof byte[])
 43  
             {
 44  0
                 data = (byte[]) src;
 45  
             }
 46  
             else
 47  
             {
 48  0
                 data = SerializationUtils.serialize((Serializable) src);
 49  
             }
 50  0
             return this.getStrategy().compressByteArray(data);
 51  
         }
 52  0
         catch (IOException ioex)
 53  
         {
 54  0
             throw new TransformerException(this, ioex);
 55  
         }
 56  
     }
 57  
 
 58  
 }