Class CmsInputStreamDataSource

java.lang.Object
org.opencms.mail.CmsInputStreamDataSource
All Implemented Interfaces:
javax.activation.DataSource

public class CmsInputStreamDataSource extends Object implements javax.activation.DataSource
DataSource implementation that may be filled with content from an 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.

Since:
6.1.7
  • Constructor Details

    • CmsInputStreamDataSource

      public CmsInputStreamDataSource(InputStream in, String contentType, 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 Details

    • getContentType

      Specified by:
      getContentType in interface javax.activation.DataSource
      See Also:
      • DataSource.getContentType()
    • getInputStream

      Retunrs the underlying input stream of this data source.
      Specified by:
      getInputStream in interface javax.activation.DataSource
      Returns:
      the underlying input stream of this data source.
      Throws:
      IOException - if the constructor-given input stream is not "resettable" (InputStream.reset()).
      See Also:
      • DataSource.getInputStream()
    • getName

      public String getName()
      Specified by:
      getName in interface javax.activation.DataSource
      See Also:
      • DataSource.getName()
    • 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 interface javax.activation.DataSource
      See Also:
      • DataSource.getOutputStream()