1 23 24 package org.infoglue.cms.util.mail; 25 26 import java.io.ByteArrayInputStream ; 27 import java.io.IOException ; 28 import java.io.InputStream ; 29 import java.io.OutputStream ; 30 import java.io.UnsupportedEncodingException ; 31 32 import javax.activation.DataSource ; 33 34 37 38 public class StringDataSource implements DataSource 39 { 40 private byte[] data; 41 private String type; 42 private String encoding; 43 44 public StringDataSource(String data, String type) 45 { 46 try 47 { 48 this.data = data.getBytes("iso-8859-1"); 49 } 50 catch (UnsupportedEncodingException uex) 51 { 52 } 53 54 this.type = type; 55 } 56 57 public StringDataSource(String data, String type, String encoding) 58 { 59 try 60 { 61 this.data = data.getBytes(encoding); 62 } 63 catch (UnsupportedEncodingException uex) 64 { 65 } 66 67 this.type = type; 68 this.encoding = encoding; 69 } 70 71 public InputStream getInputStream() throws IOException 72 { 73 if (data == null) 74 throw new IOException ("no data"); 75 76 return new ByteArrayInputStream (data); 77 } 78 79 public OutputStream getOutputStream() throws IOException 80 { 81 throw new IOException ("cannot do this"); 82 } 83 84 public String getContentType() 85 { 86 return type; 87 } 88 89 public String getName() 90 { 91 return "dummy"; 92 } 93 } | Popular Tags |