Oracle Fusion Middleware User Messaging Service 11.1.1.7.0 Java API Reference
E14011-05

oracle.sdp.messaging.util
Class ByteArrayDataSource

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

public class ByteArrayDataSource
extends java.lang.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:

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, java.lang.String contentType)
          Create a ByteArrayDataSource using the provided byte content and contentType.
ByteArrayDataSource(InputStream stream, java.lang.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.
 java.lang.String getContentType()
           
 InputStream getInputStream()
           
 java.lang.String getName()
           
 OutputStream getOutputStream()
          Get an OutputStream for this DataSource.
 void setName(java.lang.String name)
           
 void writeTo(OutputStream os)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ByteArrayDataSource

public ByteArrayDataSource(InputStream stream,
                           java.lang.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,
                           java.lang.String contentType)
Create a ByteArrayDataSource using the provided byte 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
Specified by:
getInputStream in interface javax.activation.DataSource
Throws:
IOException

getName

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

setName

public void setName(java.lang.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:

Oracle Fusion Middleware User Messaging Service 11.1.1.7.0 Java API Reference
E14011-05

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