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

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

commit ac8d2ebe97c04b6ae68e38a17a1ee2622a7d54dc
Author: Benoit Tellier <[email protected]>
AuthorDate: Fri Mar 22 11:23:29 2019 +0700

    MAILBOX-385 Get rid of DeletedMessageWithContent
---
 .../james/vault/DeletedMessageWithContent.java     | 59 ----------------------
 .../apache/james/vault/DeletedMessageZipper.java   | 42 +++++----------
 2 files changed, 12 insertions(+), 89 deletions(-)

diff --git 
a/mailbox/plugin/deleted-messages-vault/src/main/java/org/apache/james/vault/DeletedMessageWithContent.java
 
b/mailbox/plugin/deleted-messages-vault/src/main/java/org/apache/james/vault/DeletedMessageWithContent.java
deleted file mode 100644
index b8ce977..0000000
--- 
a/mailbox/plugin/deleted-messages-vault/src/main/java/org/apache/james/vault/DeletedMessageWithContent.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-
-package org.apache.james.vault;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-/**
- * This class carries a {@link org.apache.james.vault.DeletedMessage}
- * and its data inside an InputStream.
- *
- * The InputStream is created and maintained by the callers.
- */
-public class DeletedMessageWithContent implements AutoCloseable {
-
-    private final DeletedMessage deletedMessage;
-    private final InputStream content;
-
-    public DeletedMessageWithContent(DeletedMessage deletedMessage, 
InputStream content) {
-        this.deletedMessage = deletedMessage;
-        this.content = content;
-    }
-
-    public DeletedMessage getDeletedMessage() {
-        return deletedMessage;
-    }
-
-    /**
-     * Returns the original InputStream passed to the constructor.
-     * Thus, if the InputStream is already closed by the callers, it cannot be 
reused
-     *
-     * @return content
-     */
-    public InputStream getContent() {
-        return content;
-    }
-
-    @Override
-    public void close() throws IOException {
-        content.close();
-    }
-}
diff --git 
a/mailbox/plugin/deleted-messages-vault/src/main/java/org/apache/james/vault/DeletedMessageZipper.java
 
b/mailbox/plugin/deleted-messages-vault/src/main/java/org/apache/james/vault/DeletedMessageZipper.java
index 4f00e46..cad293f 100644
--- 
a/mailbox/plugin/deleted-messages-vault/src/main/java/org/apache/james/vault/DeletedMessageZipper.java
+++ 
b/mailbox/plugin/deleted-messages-vault/src/main/java/org/apache/james/vault/DeletedMessageZipper.java
@@ -23,7 +23,6 @@ import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
-import java.util.Optional;
 import java.util.stream.Stream;
 
 import org.apache.commons.compress.archivers.zip.ExtraFieldUtils;
@@ -33,18 +32,14 @@ import org.apache.commons.io.IOUtils;
 import org.apache.james.mailbox.backup.MessageIdExtraField;
 import org.apache.james.mailbox.backup.SizeExtraField;
 import org.apache.james.mailbox.model.MessageId;
-import org.apache.james.util.OptionalUtils;
-import org.reactivestreams.Publisher;
 
 import com.github.fge.lambdas.Throwing;
+import com.github.fge.lambdas.consumers.ThrowingConsumer;
 import com.google.common.annotations.VisibleForTesting;
 
-import reactor.core.publisher.Mono;
-
 public class DeletedMessageZipper {
-
     interface DeletedMessageContentLoader {
-        Publisher<InputStream> load(DeletedMessage deletedMessage);
+        InputStream load(DeletedMessage deletedMessage);
     }
 
     DeletedMessageZipper() {
@@ -52,51 +47,38 @@ public class DeletedMessageZipper {
         ExtraFieldUtils.register(SizeExtraField.class);
     }
 
-    public void zip(DeletedMessageContentLoader contentLoader, 
Stream<DeletedMessage> deletedMessages,
-                    OutputStream outputStream) throws IOException {
+    public void zip(DeletedMessageContentLoader contentLoader, 
Stream<DeletedMessage> deletedMessages, OutputStream outputStream) throws 
IOException {
         try (ZipArchiveOutputStream zipOutputStream = 
newZipArchiveOutputStream(outputStream)) {
-            deletedMessages
-                .map(message -> messageWithContent(message, contentLoader))
-                .flatMap(OptionalUtils::toStream)
-                .forEach(Throwing.<DeletedMessageWithContent>consumer(
-                    messageWithContent -> putMessageToEntry(zipOutputStream, 
messageWithContent)).sneakyThrow());
+            ThrowingConsumer<DeletedMessage> putInZip = message -> 
putMessageToEntry(zipOutputStream, message, contentLoader);
+
+            deletedMessages.forEach(Throwing.consumer(putInZip).sneakyThrow());
 
             zipOutputStream.finish();
         }
     }
 
     @VisibleForTesting
-    Optional<DeletedMessageWithContent> messageWithContent(DeletedMessage 
message, DeletedMessageContentLoader loader) {
-        return Mono.from(loader.load(message))
-            .map(messageContent -> new DeletedMessageWithContent(message, 
messageContent))
-            .blockOptional();
-    }
-
-    @VisibleForTesting
     ZipArchiveOutputStream newZipArchiveOutputStream(OutputStream 
outputStream) {
         return new ZipArchiveOutputStream(outputStream);
     }
 
     @VisibleForTesting
-    void putMessageToEntry(ZipArchiveOutputStream zipOutputStream, 
DeletedMessageWithContent message) throws IOException {
-        try (DeletedMessageWithContent closableMessage = message) {
-            ZipArchiveEntry archiveEntry = createEntry(zipOutputStream, 
message);
-            zipOutputStream.putArchiveEntry(archiveEntry);
+    void putMessageToEntry(ZipArchiveOutputStream zipOutputStream, 
DeletedMessage message, DeletedMessageContentLoader contentLoader) throws 
IOException {
+        try (InputStream content = contentLoader.load(message)) {
+            zipOutputStream.putArchiveEntry(createEntry(zipOutputStream, 
message));
 
-            IOUtils.copy(message.getContent(), zipOutputStream);
+            IOUtils.copy(content, zipOutputStream);
 
             zipOutputStream.closeArchiveEntry();
         }
     }
 
     @VisibleForTesting
-    ZipArchiveEntry createEntry(ZipArchiveOutputStream zipOutputStream,
-                                        DeletedMessageWithContent fullMessage) 
throws IOException {
-        DeletedMessage message = fullMessage.getDeletedMessage();
+    ZipArchiveEntry createEntry(ZipArchiveOutputStream zipOutputStream, 
DeletedMessage message) throws IOException {
         MessageId messageId = message.getMessageId();
 
         ZipArchiveEntry archiveEntry = (ZipArchiveEntry) 
zipOutputStream.createArchiveEntry(new File(messageId.serialize()), 
messageId.serialize());
-        archiveEntry.addExtraField(new 
MessageIdExtraField(messageId.serialize()));
+        archiveEntry.addExtraField(new MessageIdExtraField(messageId));
         archiveEntry.addExtraField(new SizeExtraField(message.getSize()));
 
         return archiveEntry;


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to