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 UUEncoder extends AbstractTransformer 24 { 25 28 private static final long serialVersionUID = 4074142466316499186L; 29 30 private sun.misc.UUEncoder encoder; 31 32 public UUEncoder() 33 { 34 registerSourceType(String .class); 35 registerSourceType(byte[].class); 36 setReturnClass(String .class); 37 encoder = new sun.misc.UUEncoder(); 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 |