1 10 11 26 27 package org.mule.providers.email.transformers; 28 29 import org.apache.commons.io.output.ByteArrayOutputStream; 30 31 import javax.activation.DataSource ; 32 33 import java.io.ByteArrayInputStream ; 34 import java.io.IOException ; 35 import java.io.InputStream ; 36 import java.io.OutputStream ; 37 38 public class PlainTextDataSource implements DataSource 39 { 40 public static final String CONTENT_TYPE = "text/plain"; 41 42 private final String name; 43 private byte[] data; 44 private ByteArrayOutputStream os; 45 46 public PlainTextDataSource(String name, String data) 47 { 48 this.name = name; 49 this.data = data == null ? null : data.getBytes(); 50 os = new ByteArrayOutputStream(); 51 } 53 public String getName() 54 { 55 return name; 56 } 58 public String getContentType() 59 { 60 return CONTENT_TYPE; 61 } 63 public InputStream getInputStream() throws IOException 64 { 65 if (os.size() != 0) 66 { 67 data = os.toByteArray(); 68 } 69 return new ByteArrayInputStream (data == null ? new byte[0] : data); 70 } 72 public OutputStream getOutputStream() throws IOException 73 { 74 if (os.size() != 0) 75 { 76 data = os.toByteArray(); 77 } 78 return new ByteArrayOutputStream(); 79 } 81 } | Popular Tags |