This is an automated email from the ASF dual-hosted git repository.

aduprat pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 55257ba20f52d0d91043e2f6733d77209520e2d7
Author: Matthieu Baechler <matth...@apache.org>
AuthorDate: Fri Feb 15 15:16:34 2019 +0100

    JAMES-2816 Use buffered streams to handle mails
    
        x3 improvement in micro-benchmark, should be around 5% improvement in 
real life
        appendMessage reported to take 8.51% in a flamegraph
---
 .../java/org/apache/james/mailbox/store/StoreMessageManager.java   | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git 
a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
 
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
index 8c32c55..5015d67 100644
--- 
a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
+++ 
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
@@ -22,6 +22,8 @@ package org.apache.james.mailbox.store;
 import static 
org.apache.james.mailbox.extension.PreDeletionHook.DeleteOperation;
 import static 
org.apache.james.mailbox.store.mail.AbstractMessageMapper.UNLIMITED;
 
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
@@ -102,7 +104,6 @@ import com.github.steveash.guavate.Guavate;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSortedMap;
-
 import reactor.core.publisher.Flux;
 import reactor.core.publisher.Mono;
 import reactor.core.scheduler.Schedulers;
@@ -339,7 +340,8 @@ public class StoreMessageManager implements MessageManager {
             // source for the InputStream
             file = File.createTempFile("imap", ".msg");
             try (FileOutputStream out = new FileOutputStream(file);
-                 TeeInputStream tmpMsgIn = new TeeInputStream(msgIn, out);
+                 BufferedOutputStream bufferedOut = new 
BufferedOutputStream(out);
+                 BufferedInputStream tmpMsgIn = new BufferedInputStream(new 
TeeInputStream(msgIn, bufferedOut));
                  BodyOffsetInputStream bIn = new 
BodyOffsetInputStream(tmpMsgIn)) {
                 // Disable line length... This should be handled by the smtp 
server
                 // component and not the parser itself
@@ -433,6 +435,7 @@ public class StoreMessageManager implements MessageManager {
                     // the file now
                     // via the TeeInputStream
                 }
+                bufferedOut.close();
                 int bodyStartOctet = (int) bIn.getBodyStartOffset();
                 if (bodyStartOctet == -1) {
                     bodyStartOctet = 0;


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org

Reply via email to