james-mime4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oleg Kalnichevski <ol...@apache.org>
Subject Re: How to avoid allocating large byte-arrays for large messages
Date Tue, 22 Sep 2015 15:30:11 GMT
On Mon, 2015-09-21 at 18:30 +0200, Andreas Joseph Krogh wrote:
> Hi all.
>  
> We're using mime4j to read/parse messages and storing them in a
> database. For large messages we get OutOfMemoryErrors because
> BasicBodyFactory and BasicBinaryBody operate on byte[].
>  
> I see on this page: https://james.apache.org/mime4j/
> that the Message-class is referenced which according to the JavaDoc
> operate on streams which looks like it would fit perfect for us. The
> problem is that I cannot find this class anywhere.
>  
> We're using the following code to parse an input-stream:
>  
> val messageBuilder = new DefaultMessageBuilder()
> val mimeConfig = new MimeConfig()
> mimeConfig.setMaxContentLen(-1) // disable
> mimeConfig.setMaxLineLen(-1) // disable
> mimeConfig.setMaxHeaderCount(-1) // disable
> mimeConfig.setMaxHeaderLen(-1) // disable
> 
> messageBuilder.setMimeEntityConfig(mimeConfig)
> val mimeMessage: Message = messageBuilder.parseMessage(is)
>  
>  
> Can anyone please point me to the correct dependencies to be able to
> use the Message-class instead, and hopefully some code-example of how
> to use it to accomplish the same as the code above except with
> hopefully a lot less memory-usage?
>  

Consider using MimeStreamParser directly (similar to SAX) instead of
using DOM.

http://james.apache.org/mime4j/index.html
http://james.apache.org/mime4j/apidocs/org/apache/james/mime4j/parser/MimeStreamParser.html

Oleg



Mime
View raw message