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 ByteArrayDataSource

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

All Implemented Interfaces:
  Serializable, javax.activation.DataSource

    public class ByteArrayDataSource

extends Object
implements javax.activation.DataSource, Serializable

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

  Example:

  - Plain Text Message:

         Message message = MessageFactory.getInstance().createMessage();
         byte[] myImageBytes;
         // Initialized image bytes
         ByteArrayDataSource imageSource = new ByteArrayDataSource(myImageBytes, "image/jpeg");
         message.setDataHandler(new DataHandler(imageSource));

  This mechanism is the only one guaranteed to work with Messaging. Setting binary content directly using Message.setContent(Object content, String contentType) or MimeBodyPart.setContent(Object content, String contentType) is unlikely to work correctly. 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.
See Also:
  Serialized Form

Constructor Summary
`ByteArrayDataSource(byte[] content, String contentType)` Create a ByteArrayDataSource using the provided byte content and contentType.
`ByteArrayDataSource(InputStream stream, String contentType)` Create a ByteArrayDataSource using the provided InputStream and contentType.

Method Summary
`byte[]` | `getBytes()` Get the content of this DataSource as a byte array.
`String` | `getContentType()`
`InputStream` | `getInputStream()`
`String` | `getName()`
`OutputStream` | `getOutputStream()` Get an OutputStream for this DataSource.
`void` | `setName(String name)`
`void` | `writeTo(OutputStream os)`

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

Constructor Detail

### ByteArrayDataSource

    public ByteArrayDataSource(InputStream stream,
                               String contentType)
                        throws IOException

  Create a ByteArrayDataSource using the provided InputStream and contentType. The InputStream will be read into an internal buffer. If required, the InputStream should be reset prior to invoking this constructor.

  Parameters:
    `stream` -
    `contentType` -
  Throws:
    `IOException`

### ByteArrayDataSource

    public ByteArrayDataSource(byte[] content,
                               String contentType)

  Create a ByteArrayDataSource using the provided byte content and contentType.

  Parameters:
    `content` -
    `contentType` -

Method Detail

### getContentType

    public String getContentType()

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

### getInputStream

    public InputStream getInputStream()
                               throws IOException

  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`

### writeTo

    public void writeTo(OutputStream os)
                 throws IOException

  Throws:
    `IOException`

### getBytes

    public byte[] getBytes()

  Get the content of this DataSource as a byte array.

  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.