1 10 11 package org.mule.providers.file.transformers; 12 13 import java.io.File ; 14 import java.io.UnsupportedEncodingException ; 15 16 import org.mule.umo.transformer.TransformerException; 17 18 21 public class FileToString extends FileToByteArray 22 { 23 26 private static final long serialVersionUID = -5376852963195290731L; 27 28 public FileToString() 29 { 30 registerSourceType(File .class); 31 registerSourceType(byte[].class); 32 setReturnClass(String .class); 33 } 34 35 43 public Object doTransform(Object src, String encoding) throws TransformerException 44 { 45 byte[] bytes; 46 47 if (src instanceof byte[]) 48 { 49 bytes = (byte[])src; 50 } 51 else 52 { 53 bytes = (byte[])super.doTransform(src, encoding); 54 } 55 56 try 57 { 58 return new String (bytes, encoding); 59 } 60 catch (UnsupportedEncodingException uee) 61 { 62 throw new TransformerException(this, uee); 63 } 64 } 65 } 66 | Popular Tags |