public class CmsInputStreamDataSource extends java.lang.Object implements javax.activation.DataSource
InputStream
.
It's intended use is for creation of mail attachments from strings without having to create RFS
or VFS resources. Note that this data source will only support read operations and operations
related to writing will throw an UnsupportedOperationException
.
Constructor and Description |
---|
CmsInputStreamDataSource(java.io.InputStream in,
java.lang.String contentType,
java.lang.String name)
Constructor with mandatory input stream, content type and name.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
getContentType() |
java.io.InputStream |
getInputStream()
Retunrs the underlying input stream of this data source.
|
java.lang.String |
getName() |
java.io.OutputStream |
getOutputStream()
Don't use this method, VFS resources can't be written using this datasource class.
|
public CmsInputStreamDataSource(java.io.InputStream in, java.lang.String contentType, java.lang.String name)
Note that the given input stream has to be resettable. During a mail creation and transmission cycle it is potentially read twice (commons-email-1.0.jar in combination with activation.jar) and the 2nd time the actual transport to the serial data to transmit is done. So a reset will be made here whenever the internal input stream is retrieved to avoid that the attachments remain empty.
The contentType argument should always be a valid MIME type. It is suggested that it is "application/octet-stream" if the DataSource implementation can not determine the data type. For textual data it should be "text/<subtype>; charset=<encoding>" to give a hint about the ecoding. Note that some textual documents like xml have their own encoding directive contained and the charset given here (for the mail part header) should not be different from the contained one.
in
- the underlying source of data.contentType
- the correct MIME type of the data along with the charset in the form of a
string (see comment above).name
- the name that describes the data in the underyling input stream. E.g. the name of
a file that the input stream reads from.public java.lang.String getContentType()
getContentType
in interface javax.activation.DataSource
DataSource.getContentType()
public java.io.InputStream getInputStream() throws java.io.IOException
getInputStream
in interface javax.activation.DataSource
java.io.IOException
- if the constructor-given input stream is not "resettable" (InputStream.reset()
).DataSource.getInputStream()
public java.lang.String getName()
getName
in interface javax.activation.DataSource
DataSource.getName()
public java.io.OutputStream getOutputStream()
This method will just return a new
.
ByteArrayOutputStream
getOutputStream
in interface javax.activation.DataSource
DataSource.getOutputStream()