Class CmsInputStreamDataSource
- java.lang.Object
-
- org.opencms.mail.CmsInputStreamDataSource
-
- All Implemented Interfaces:
javax.activation.DataSource
public class CmsInputStreamDataSource extends java.lang.Object implements javax.activation.DataSource
DataSource implementation that may be filled with content from anInputStream
.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
.- Since:
- 6.1.7
-
-
Constructor Summary
Constructors Constructor Description CmsInputStreamDataSource(java.io.InputStream in, java.lang.String contentType, java.lang.String name)
Constructor with mandatory input stream, content type and name.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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.
-
-
-
Constructor Detail
-
CmsInputStreamDataSource
public CmsInputStreamDataSource(java.io.InputStream in, java.lang.String contentType, java.lang.String name)
Constructor with mandatory input stream, content type and 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.
- Parameters:
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.
-
-
Method Detail
-
getContentType
public java.lang.String getContentType()
- Specified by:
getContentType
in interfacejavax.activation.DataSource
- See Also:
DataSource.getContentType()
-
getInputStream
public java.io.InputStream getInputStream() throws java.io.IOException
Retunrs the underlying input stream of this data source.- Specified by:
getInputStream
in interfacejavax.activation.DataSource
- Returns:
- the underlying input stream of this data source.
- Throws:
java.io.IOException
- if the constructor-given input stream is not "resettable" (InputStream.reset()
).- See Also:
DataSource.getInputStream()
-
getName
public java.lang.String getName()
- Specified by:
getName
in interfacejavax.activation.DataSource
- See Also:
DataSource.getName()
-
getOutputStream
public java.io.OutputStream getOutputStream()
Don't use this method, VFS resources can't be written using this datasource class.This method will just return a new
.ByteArrayOutputStream
- Specified by:
getOutputStream
in interfacejavax.activation.DataSource
- See Also:
DataSource.getOutputStream()
-
-