atom feed5 messages in Large SAAJ attachments and OutOfM...
FromSent OnAttachments
yann...@gmail.comAug 8, 2011 2:36 am 
Dmitry KatsuboAug 9, 2011 10:03 am 
Kumar JayantiAug 9, 2011 10:12 am 
yann BlazartAug 9, 2011 10:49 am 
Dmitry KatsuboAug 11, 2011 2:29 pm 
Subject:Re: Large SAAJ attachments and OutOfMemoryError
From:Kumar Jayanti (
Date:Aug 9, 2011 10:12:48 am

When receiving incoming messagges SAAJ can utilize MimePull Parser which stores
the attachment to file system.

not sure if this will help in this case.

On 09-Aug-2011, at 10:33 PM, Dmitry Katsubo wrote:

On 08.08.2011 11:36, wrote:

Hi ! As I ve no responses, I'm writing to the list.

I have open a bug As nobody take it, I've writed a post on the forum, but no more response...

So, when you modify an outcome message with a Handler, and when you deal with large attachment,you have a problem, because in the classe, we have the following method used by MimeCodec and MTOMCodec :

public void writeTo(OutputStream os) throws IOException { os.write(asByteArray()); }

The document is entirely mounted in memory !

Is anybody can make a patch to correct this ?

Strange, that you haven't got OutOfMemory before (or you still haven't got it?).

Tracing back the source:

SAAJMessage.SAAJAttachment -> AttachmentPartImpl -> MimeBodyPart, and then in constructor we have a choice:

(a) SharedInputStream: Can somehow clone the contents (e.g. in case the attachment was saved to file / temporary location) (b) any other: ByteOutputStream is created (the contents is completely in memory).

As SharedInputStream has no implementors, see also the code comment:

// SAAJ doesn't utilize this, but I think it should.

so I suppose (b) is the common case which means attachments are always stored in memory.