bburtin.47737078@... wrote:
> --- Bill Shannon <
bill.shannon@... wrote:
> Boris Burtin wrote:
>>> Is
> there a way to get the entire content of a MimeMessage (headers + content)
>
>>> as an InputStream? My current plan is to write custom code that essentially
>
>>> duplicates the logic in MimeMessage.writeTo(). Please let me know if
> there's
>>> already an API that does this that I missed.
>> PipedInputStream?
> Have a thread write it to one end of the pipe and you
>> can read it out
> the other end of the pipe.
>> Or write it to a ByteArrayOutputStream and
> then read it back with a
>> ByteArrayInputStream.
>
> Thanks Bill. I don't
> think that either of those options will work for me. PipedInputStream requires
> two threads. I don't really want to start a new thread every time I need
> to get the data out of a MimeMessage. ByteArrayOutputStream will load the
> entire content into memory, which won't fly with large messages. No worries,
> I'll just roll my own, using MimeMessage.writeTo() as a template.
It's not that easy.
There's a series of delegations to content handlers. The content handlers
are all prepared to write their content to a stream, not produce a stream
from which to read content. Similarly, the content encoders work by wrapping
output streams. Sure, you can replace all this machinery, it's only software
after all. But getting it to work in all cases is going to be a significant
amount of work.
If you think the cost of starting a thread is too much, you can always use
a thread pool. See java.util.concurrent.ThreadPoolExecutor.
===========================================================================
To unsubscribe, send email to
listserv@... and include in the body
of the message "signoff JAVAMAIL-INTEREST". For general help, send email to
listserv@... and include in the body of the message "help".