Oracle Fusion Middleware User Messaging Service 11.1.1.6.0 Java API Reference
E14011-04

oracle.sdp.messaging.util
Class StringDataSource

java.lang.Object
  extended by oracle.sdp.messaging.util.StringDataSource
All Implemented Interfaces:
javax.activation.DataSource

public class StringDataSource
extends java.lang.Object
implements javax.activation.DataSource

Since:
release specific (what release of product did this appear in) StringDataSource is an implementation of javax.activation.DataSource suitable for use with text content. Use of a DataHandler containing a StringDataSource is the recommended approach for passing text content to any of the Messaging client interfaces.

Examples:

This mechanism is recommended instead of setting content directly using Message.setContent(Object content, String contentType) or MimeBodyPart.setContent(Object content, String contentType). The behavior of those methods may vary widely depending on how various components have altered the JavaMail and Java Activation Framework configuration in the runtime environment. While setting content directly is reasonably safe for text/plain content, other content types such as text/xml and text/x-* are unlikely to function correctly. At any point where a character set is required (either to interpret a byte[] or InputStream in a constructor, or to generate an InpuStream), the charset will be determined in the following order of precedence:
  1. The value of the "charset" parameter to the contentType provided in the constructor, if any
  2. The value of the "mail.mime.charset" System property, if any
  3. The System default charset, equal to the value of the "file.encoding" System property

Constructor Summary
StringDataSource(byte[] bytes, java.lang.String contentType)
          Create a StringDataSource using the provided byte array.
StringDataSource(InputStream stream, java.lang.String contentType)
          Create a StringDataSource using the provided InputStream.
StringDataSource(java.lang.String content, java.lang.String contentType)
          Create a StringDataSource with the provided String content and contentType.
 
Method Summary
 java.lang.String getContentType()
           
 InputStream getInputStream()
          Get an InputStream containing the data for this DataSource.
 java.lang.String getName()
           
 OutputStream getOutputStream()
          Get an OutputStream for this DataSource.
 java.lang.String getString()
          Get the content of this DataSource as a String.
 void setName(java.lang.String name)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringDataSource

public StringDataSource(byte[] bytes,
                        java.lang.String contentType)
Create a StringDataSource using the provided byte array. The bytes will be interepreted as a String according to charset determined from either the contentType parameter or the default charset (see above).

Parameters:
bytes -
contentType -

StringDataSource

public StringDataSource(InputStream stream,
                        java.lang.String contentType)
Create a StringDataSource using the provided InputStream. The InputStream content will be interpreted as a String according to the charset determined from the contentType paremter, or the default charset (see above).

Parameters:
stream -
contentType -

StringDataSource

public StringDataSource(java.lang.String content,
                        java.lang.String contentType)
Create a StringDataSource with the provided String content and contentType.

Parameters:
content -
contentType -
Method Detail

getContentType

public java.lang.String getContentType()
Specified by:
getContentType in interface javax.activation.DataSource

getInputStream

public InputStream getInputStream()
                           throws IOException
Get an InputStream containing the data for this DataSource.

Specified by:
getInputStream in interface javax.activation.DataSource
Throws:
IOException

getName

public java.lang.String getName()
Specified by:
getName in interface javax.activation.DataSource

getOutputStream

public OutputStream getOutputStream()
                             throws IOException
Get an OutputStream for this DataSource. As per the interface for DataSource, this method is not required to be supported. This method always throws an IOException.

Specified by:
getOutputStream in interface javax.activation.DataSource
Throws:
IOException

getString

public java.lang.String getString()
Get the content of this DataSource as a String.

Returns:

setName

public void setName(java.lang.String name)

Oracle Fusion Middleware User Messaging Service 11.1.1.6.0 Java API Reference
E14011-04

Copyright © 2009, 2011 Oracle and/or its affiliates. All rights reserved.