Control what DataContentHandler to use for a MimeMessage attachment?
<p>I am creating an attachment to <code>MimeMessage</code> for a Tiff image with a byte array.</p>

<pre><code>ByteArrayOutputStream out = new ByteArrayOutputStream();
MimeBodyPart body = new MimeBodyPart();
body.setContent(tiffByteArray, "image/tiff");
body.setDisposition("attachment");
body.setFileName(filename);
MimeMultipart multipart = new MimeMultipart();
multipart.addBodyPart(body);
MimeMessage message = new MimeMessage(Session.getDefaultInstance(System.getProperties()));
message.setContent(multipart);
message.writeTo(out);
String mimeContent = out.toString();
</code></pre>

<p>This normally works.  The image is converted to a base64 string in the message.  However, at some point something on the system occurs and this piece of code starts using <code>com.sun.xml.internal.messaging.saaj.soap.ImageDataContentHandler</code>.  This particular converted expects an <code>java.awt.Image</code> object as opposed to a byte array (<a href="http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b27/com/sun/xml/internal/messaging/saaj/soap/ImageDataContentHandler.java#120" rel="nofollow" title="relevant source">relevant source</a>).  I get the following error:</p>

<blockquote>
  <p>Unable to encode the image to a stream ImageDataContentHandler requires Image object, was given object of type class [B</p>
</blockquote>

<p>I can see that you can set the <code>javax.activation.DataHandler</code> on the <code>javax.mail.internet.MimeMessage</code> and in the <code>DataHandler</code> you can set the <code>javax.activation.DataContentHandlerFactory</code>, but I'm not sure what to set it to.</p>

<p>Is there a way to force a byte array to be converted to a base64 encoded String regardless of the mime type?</p>