001    package railo.runtime.net.smtp;
002    
003    import java.io.ByteArrayInputStream;
004    import java.io.IOException;
005    import java.io.InputStream;
006    import java.io.OutputStream;
007    
008    import javax.activation.DataSource;
009    
010    public final class StringDataSource implements DataSource {
011    
012            private String text;
013            private String ct;
014            private String charset;
015    
016            public StringDataSource(String text, String ct, String charset) {
017                    this.text=text;
018                    this.ct=ct;
019                    this.charset=charset;
020            }
021    
022            /**
023             * @see javax.activation.DataSource#getContentType()
024             */
025            public String getContentType() {
026                    return ct;
027            }
028    
029            /**
030             * @see javax.activation.DataSource#getInputStream()
031             */
032            public InputStream getInputStream() throws IOException {
033                    return new ByteArrayInputStream(text.getBytes(charset));
034            }
035    
036            /**
037             * @see javax.activation.DataSource#getName()
038             */
039            public String getName() {
040                    return "StringDataSource";
041            }
042    
043            /**
044             * @see javax.activation.DataSource#getOutputStream()
045             */
046            public OutputStream getOutputStream() throws IOException {
047                    throw new IOException("no access to write");
048            }
049    
050    }