Coverage Report - org.mule.transformers.simple.ByteArrayToString
 
Classes in this File Line Coverage Branch Coverage Complexity
ByteArrayToString
0%
0/10
0%
0/4
3.5
 
 1  
 /*
 2  
  * $Id: ByteArrayToString.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.simple;
 12  
 
 13  
 import org.mule.config.i18n.MessageFactory;
 14  
 import org.mule.transformers.AbstractTransformer;
 15  
 import org.mule.umo.transformer.TransformerException;
 16  
 
 17  
 import java.io.UnsupportedEncodingException;
 18  
 
 19  
 /**
 20  
  * <code>ByteArrayToString</code> converts a byte array into a String.
 21  
  */
 22  
 public class ByteArrayToString extends AbstractTransformer
 23  
 {
 24  
 
 25  
     public ByteArrayToString()
 26  0
     {
 27  0
         registerSourceType(byte[].class);
 28  0
         registerSourceType(String.class);
 29  0
         setReturnClass(String.class);
 30  0
     }
 31  
 
 32  
     public Object doTransform(Object src, String encoding) throws TransformerException
 33  
     {
 34  0
         if (src instanceof String)
 35  
         {
 36  0
             return src;
 37  
         }
 38  
         else
 39  
         {
 40  
             try
 41  
             {
 42  0
                 return new String((byte[]) src, encoding);
 43  
             }
 44  0
             catch (UnsupportedEncodingException e)
 45  
             {
 46  0
                 throw new TransformerException(MessageFactory
 47  
                     .createStaticMessage("Unable to convert byte[] to String."), e);
 48  
             }
 49  
         }
 50  
     }
 51  
 }