Coverage Report - org.mule.transformers.simple.ByteArrayToObject
 
Classes in this File Line Coverage Branch Coverage Complexity
ByteArrayToObject
71%
5/7
100%
2/2
6
 
 1  
 /*
 2  
  * $Id: ByteArrayToObject.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.umo.transformer.TransformerException;
 14  
 
 15  
 import java.io.ObjectStreamConstants;
 16  
 
 17  
 /**
 18  
  * <code>ByteArrayToObject</code> works in the same way as
 19  
  * <code>ByteArrayToSerializable</code> but checks if th byte array is a serialised
 20  
  * object and if not will return a String created from the bytes is the returnType on
 21  
  * the transformer.
 22  
  */
 23  26
 public class ByteArrayToObject extends ByteArrayToSerializable
 24  
 {
 25  
 
 26  
     // @Override
 27  
     public Object doTransform(Object src, String encoding) throws TransformerException
 28  
     {
 29  14
         byte[] bytes = (byte[]) src;
 30  
 
 31  14
         if (bytes[0] == (byte) ((ObjectStreamConstants.STREAM_MAGIC >>> 8) & 0xFF))
 32  
         {
 33  8
             return super.doTransform(src, encoding);
 34  
         }
 35  
         else
 36  
         {
 37  
             try
 38  
             {
 39  6
                 return new String(bytes, encoding);
 40  
             }
 41  0
             catch (Exception e)
 42  
             {
 43  0
                 throw new TransformerException(this, e);
 44  
             }
 45  
         }
 46  
     }
 47  
 
 48  
 }