1 10 11 package org.mule.transformers.simple; 12 13 import java.io.UnsupportedEncodingException ; 14 15 import org.mule.config.i18n.Message; 16 import org.mule.transformers.AbstractTransformer; 17 import org.mule.umo.transformer.TransformerException; 18 19 25 26 public class ByteArrayToString extends AbstractTransformer 27 { 28 29 private static final long serialVersionUID = -9033005899991305308L; 30 31 public ByteArrayToString() 32 { 33 registerSourceType(byte[].class); 34 registerSourceType(String .class); 35 setReturnClass(String .class); 36 } 37 38 public Object doTransform(Object src, String encoding) throws TransformerException 39 { 40 if (src instanceof String ) 41 { 42 return src; 43 } 44 else 45 { 46 try 47 { 48 return new String ((byte[])src, encoding); 49 } 50 catch (UnsupportedEncodingException e) 51 { 52 throw new TransformerException( 53 Message.createStaticMessage("Unable to convert byte[] to String."), e); 54 } 55 } 56 } 57 } 58 | Popular Tags |