package com.perforce.reviewer; import java.io.*; import javax.activation.*; /** * Implements a <code>DataSource</code> from a <code>String</code>. This * is useful for creating an HTML DataSource that can be used in sending * out e-mail. * <p> * This class is used by the built-in <code>MailListener</code> class. It * is public, so it can be used by other <code>ChangeListener</code> * implementations. Take a look at the package sources to see how * <code>MailListener</code> uses it. * <p> * Most users of the <code>Reviewer</code> may not need to be concerned * with this class. * * @see ChangeListener * @see javax.activation.DataSource * @author <a href="mailto:david@markley.cc">David Markley</a> * @version $Date: 2002/01/11 $ $Revision: #2 $ */ public class StringDataSource implements DataSource { private final static String ENCODING = "iso-8859-1"; private final static String TYPE = "text/plain"; private String encoding = ENCODING; private String type = TYPE; private byte[] data; /* Create a DataSource from a String */ public StringDataSource(String data) { this(data, TYPE, ENCODING); } /* Create a DataSource from a String */ public StringDataSource(String data, String type) { this(data, type, ENCODING); } /* Create a DataSource from a String */ public StringDataSource(String data, String type, String encoding) { this.encoding = encoding; this.type = type; try { this.data = data.getBytes(this.encoding); } catch (UnsupportedEncodingException uex) { } } /** * Return an <code>InputStream</code> for the data. */ public InputStream getInputStream() throws IOException { if (data == null) throw new IOException("No data"); return new ByteArrayInputStream(data); } /** * Required to implement <code>DataSource</code>, but invalid. This will * always throw an <code>IOException</code>. */ public OutputStream getOutputStream() throws IOException { throw new IOException("invalid"); } public String getContentType() { return this.type; } public void setContentType(String type) { this.type = type; } public String getEncoding() { return this.encoding; } public void setEncoding(String encoding) { this.encoding = encoding; } public String getName() { return "string data"; } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 1682 | rmg | Add David's Java Reviewer to //public. | ||
//guest/david_markley/reviewer/com/perforce/reviewer/StringDataSource.java | |||||
#2 | 1670 | David Markley |
Completed the user documentation in preperation for the public depot. Includes example configuration for the Java Reviewer. |
||
#1 | 1368 | David Markley |
Needed access to the Properties within the Env for the Reviewer. Moved things around to create the com.perforce.reviewer package. |