1 10 11 package org.mule.transformers.codec; 12 13 import org.mule.transformers.AbstractTransformer; 14 import org.mule.umo.transformer.TransformerException; 15 16 23 public class UCEncoder extends AbstractTransformer 24 { 25 28 private static final long serialVersionUID = 1120873588501386458L; 29 30 private sun.misc.UCEncoder encoder; 31 32 public UCEncoder() 33 { 34 registerSourceType(String .class); 35 registerSourceType(byte[].class); 36 setReturnClass(String .class); 37 encoder = new sun.misc.UCEncoder(); 38 } 39 40 45 public Object doTransform(Object src, String encoding) throws TransformerException 46 { 47 byte[] buf; 48 if (src instanceof String ) 49 { 50 buf = src.toString().getBytes(); 51 } 52 else 53 { 54 buf = (byte[])src; 55 } 56 String result = encoder.encode(buf); 57 if (getReturnClass().equals(byte[].class)) 58 { 59 return result.getBytes(); 60 } 61 return result; 62 } 63 } 64 | Popular Tags |