import java.io.*; import javax.activation.*; /** * Implements a <code>DataSource</code> from a <code>String</code>. */ 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/build/StringDataSource.java | |||||
#1 | 1362 | David Markley |
Added a Reviewer that uses the p4package Java API. Had this for a while, but it's updated and best to be checked in. Lost one hard drive today...that's enough loss for today. |