if (obj instanceof MimeBodyPart)
{
try
{
((MimeBodyPart)obj).writeTo(os);
}
catch (MessagingException ex)
{
throw new IOException(ex.getMessage());
}
}
else if (obj instanceof byte[])
{
os.write((byte[])obj);
}
else if (obj instanceof InputStream)
{
int b;
InputStream in = (InputStream)obj;
if (!(in instanceof BufferedInputStream))
{
in = new BufferedInputStream(in);
}
while ((b = in.read()) >= 0)
{
os.write(b);
}
}
else if (obj instanceof SMIMEStreamingProcessor)
{
SMIMEStreamingProcessor processor = (SMIMEStreamingProcessor)obj;
processor.write(os);
}
else
{
// TODO it would be even nicer if we could attach the object to the exception
// as well since in deeply nested messages, it is not always clear which
// part caused the problem. Thus I guess we would have to subclass the
// IOException
throw new IOException("unknown object in writeTo " + obj);
}