Re: How to get message with headers as InputStream?

View: New views
4 Messages — Rating Filter:   Alert me  

Re: How to get message with headers as InputStream?

by Boris Burtin :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

--- 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.

Boris

===========================================================================
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".

Re: How to get message with headers as InputStream?

by Bill Shannon :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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".

Parent Message unknown Re: How to get message with headers as InputStream?

by Boris Burtin :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

--- Bill Shannon <bill.shannon@... wrote:
> 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.

Yikes.  Ok, I'll investigate the PipedInputStream approach.
 It would be great to have InputStream support in a future release.  We've
had a number of requests from customers who want to send attachments that
are several hundred megabytes in size.  Having that much data in memory won't
scale.  Starting a separate thread to pipe the data will probably work, but
it's a pretty nasty workaround.

I appreciate you giving me a heads up on
the potential issues.

Thanks again,

Boris

===========================================================================
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".

Re: How to get message with headers as InputStream?

by Bill Shannon :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

bburtin.47737078@... wrote:

> --- Bill Shannon <bill.shannon@... wrote:
>> 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.
>
> Yikes.  Ok, I'll investigate the PipedInputStream approach.
>  It would be great to have InputStream support in a future release.  We've
> had a number of requests from customers who want to send attachments that
> are several hundred megabytes in size.  Having that much data in memory won't
> scale.  Starting a separate thread to pipe the data will probably work, but
> it's a pretty nasty workaround.

Nothing in JavaMail requires the entire attachment to be in memory.

Tell me again, what is it you're trying to accomplish by reading the
message text as an input stream instead of writing it to an output
stream?

And what is it you have against threads?  :-)

===========================================================================
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".