Object value, SerializationContext context)
throws IOException
{
DataHandler dh= (DataHandler)value;
//Add the attachment content to the message.
Attachments attachments= context.getCurrentMessage().getAttachmentsImpl();
if (attachments == null) {
// Attachments apparently aren't supported.
// Instead of throwing NullPointerException like
// we used to do, throw something meaningful.
throw new IOException(Messages.getMessage("noAttachments"));
}
Part attachmentPart= attachments.createAttachmentPart(dh);
AttributesImpl attrs = new AttributesImpl();
if (attributes != null && 0 < attributes.getLength())
attrs.setAttributes(attributes); //copy the existing ones.