MailDataSourcepublic class MailDataSource extends Object implements DataSourceMailDataSource implements a typed DataSource from :
an InputStream, a byte array, and a string
This is used from {@link BaseCommand#generateMail} |
Fields Summary |
---|
protected static final int | DEFAULT_BUF_SIZE | protected static final String | DEFAULT_ENCODING | protected static final String | DEFAULT_NAME | protected byte[] | data | protected String | contentType |
Constructors Summary |
---|
public MailDataSource(InputStream inputStream, String contentType)Create a datasource from an input stream // content-type
this.contentType = contentType;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
copyStream(inputStream, baos);
data = baos.toByteArray();
| public MailDataSource(byte[] data, String contentType)Create a datasource from a byte array
this.contentType = contentType;
this.data = data;
| public MailDataSource(String data, String contentType)Create a datasource from a String
this.contentType = contentType;
this.data = data.getBytes(DEFAULT_ENCODING);
|
Methods Summary |
---|
protected static int | copyStream(java.io.InputStream inputStream, java.io.OutputStream outputStream)
inputStream = new BufferedInputStream(inputStream);
outputStream = new BufferedOutputStream(outputStream);
byte[] bbuf = new byte[DEFAULT_BUF_SIZE];
int len;
int totalBytes = 0;
while ((len = inputStream.read(bbuf)) != -1) {
outputStream.write(bbuf, 0, len);
totalBytes += len;
}
outputStream.flush();
return totalBytes;
| public java.lang.String | getContentType()returns the contentType for this data source
return contentType;
| public java.io.InputStream | getInputStream()returns the inputStream
if (data == null)
throw new IOException("no data");
return new ByteArrayInputStream(data);
| public java.lang.String | getName()returns a static moniker
return DEFAULT_NAME;
| public java.io.OutputStream | getOutputStream()Not implemented
throw new IOException("getOutputStream() isn't implemented");
|
|