Coverage Report - org.mule.transformers.simple.ByteArrayToSerializable
 
Classes in this File Line Coverage Branch Coverage Complexity
ByteArrayToSerializable
67%
6/9
83%
5/6
3.5
 
 1  
 /*
 2  
  * $Id: ByteArrayToSerializable.java 7963 2007-08-21 08:53:15Z 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.simple;
 12  
 
 13  
 import org.mule.config.i18n.CoreMessages;
 14  
 import org.mule.transformers.AbstractTransformer;
 15  
 import org.mule.umo.transformer.TransformerException;
 16  
 
 17  
 import java.io.InputStream;
 18  
 
 19  
 import org.apache.commons.lang.SerializationUtils;
 20  
 
 21  
 /**
 22  
  * <code>ByteArrayToSerializable</code> converts a serialized object to its object
 23  
  * representation
 24  
  */
 25  
 public class ByteArrayToSerializable extends AbstractTransformer
 26  
 {
 27  
 
 28  
     public ByteArrayToSerializable()
 29  54
     {
 30  58
         registerSourceType(byte[].class);
 31  54
         registerSourceType(InputStream.class);
 32  54
     }
 33  
 
 34  
     public Object doTransform(Object src, String encoding) throws TransformerException
 35  
     {
 36  
         try
 37  
         {
 38  20
             if (src instanceof byte[])
 39  
             {
 40  20
                 return SerializationUtils.deserialize((byte[]) src);
 41  
             }
 42  
             else
 43  
             {
 44  0
                 return SerializationUtils.deserialize((InputStream) src);
 45  
 
 46  
             }
 47  
         }
 48  0
         catch (Exception e)
 49  
         {
 50  0
             throw new TransformerException(
 51  
                 CoreMessages.transformFailed("byte[]", "Object"), this, e);
 52  
         }
 53  
     }
 54  
 
 55  
 }