Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| Oracle Communication and Mobility Server Java API Reference E14335-01
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## oracle.sdp.parlayx.multimedia_messaging
Class StringDataSource

    java.lang.Object
      oracle.sdp.parlayx.multimedia_messaging.StringDataSource

All Implemented Interfaces:
  javax.activation.DataSource

    public class StringDataSource

extends 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:

  - Plain Text Message:

         Message message = MessageFactory.getInstance().createMessage();
         StringDataSource plainDataSource = new StringDataSource("This is a Plain Text message.", "text/plain");
         message.setDataHandler(new DataHandler(plainDataSource));

  - Text/html message with an alternative character set:

         Message message = MessageFactory.getInstance().createMessage();
         StringDataSource htmlDataSource = new StringDataSource("<html><head></head><body><b><i>This is an HTML part with a UTF-8 character: ?.</i></b></body></html>",
                         "text/html; charset=UTF-8");
         message.setDataHandler(new DataHandler(htmlDataSource));

  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, String contentType)` Create a StringDataSource using the provided byte array.
`StringDataSource(InputStream stream, String contentType)` Create a StringDataSource using the provided InputStream.
`StringDataSource(String content, String contentType)` Create a StringDataSource with the provided String content and contentType.

Method Summary
`String` | `getContentType()`
`InputStream` | `getInputStream()` Get an InputStream containing the data for this DataSource.
`String` | `getName()`
`OutputStream` | `getOutputStream()` Get an OutputStream for this DataSource.
`String` | `getString()` Get the content of this DataSource as a String.
`void` | `setName(String name)`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### StringDataSource

    public StringDataSource(String content,
                            String contentType)

  Create a StringDataSource with the provided String content and contentType.

  Parameters:
    `content` -
    `contentType` -

### StringDataSource

    public StringDataSource(byte[] bytes,
                            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,
                            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` -

Method Detail

### getContentType

    public 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 String getName()

  Specified by:
    `getName` in interface `javax.activation.DataSource`

### setName

    public void setName(String name)

### 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 String getString()

  Get the content of this DataSource as a String.

  Returns:

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2007-2009 Oracle Corporation. All Rights Reserved.