Repository: james-project
Updated Branches:
  refs/heads/master 081102eab -> 0a8c85011


JAMES-2095 optimize IO on storeAttachments


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/563a21a6
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/563a21a6
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/563a21a6

Branch: refs/heads/master
Commit: 563a21a6ad124ce62267777876fa768206949846
Parents: 081102e
Author: Luc DUZAN <[email protected]>
Authored: Mon Jul 10 14:16:46 2017 +0200
Committer: Antoine Duprat <[email protected]>
Committed: Tue Jul 25 09:28:21 2017 +0200

----------------------------------------------------------------------
 .../java/org/apache/james/mailbox/model/Attachment.java |  9 +++++++++
 .../org/apache/james/mailbox/model/AttachmentTest.java  | 12 ++++++++++++
 .../cassandra/mail/CassandraAttachmentMapper.java       |  2 +-
 3 files changed, 22 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/563a21a6/mailbox/api/src/main/java/org/apache/james/mailbox/model/Attachment.java
----------------------------------------------------------------------
diff --git 
a/mailbox/api/src/main/java/org/apache/james/mailbox/model/Attachment.java 
b/mailbox/api/src/main/java/org/apache/james/mailbox/model/Attachment.java
index 2be135a..e0f6ac2 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/model/Attachment.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/Attachment.java
@@ -107,6 +107,15 @@ public class Attachment {
         return new ByteArrayInputStream(bytes);
     }
 
+    /**
+     * Be careful the returned array is not a copy of the attachment byte 
array.
+     * Mutating it will mutate the attachment!
+     * @return the attachment content
+     */
+    public byte[] getBytes() {
+        return bytes;
+    }
+
     @Override
     public boolean equals(Object obj) {
         if (obj instanceof Attachment) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/563a21a6/mailbox/api/src/test/java/org/apache/james/mailbox/model/AttachmentTest.java
----------------------------------------------------------------------
diff --git 
a/mailbox/api/src/test/java/org/apache/james/mailbox/model/AttachmentTest.java 
b/mailbox/api/src/test/java/org/apache/james/mailbox/model/AttachmentTest.java
index 6a1c29c..53728eb 100644
--- 
a/mailbox/api/src/test/java/org/apache/james/mailbox/model/AttachmentTest.java
+++ 
b/mailbox/api/src/test/java/org/apache/james/mailbox/model/AttachmentTest.java
@@ -45,6 +45,18 @@ public class AttachmentTest {
     }
 
     @Test
+    public void getByteShouldReturnByteArrayRepresentingTheAttachment() throws 
Exception {
+        String input = "mystream";
+        Attachment attachment = Attachment.builder()
+            .bytes(input.getBytes())
+            .type("content")
+            .build();
+
+        byte[] bytes = attachment.getBytes();
+        assertThat(new String(bytes)).isEqualTo(input);
+    }
+
+    @Test
     public void streamShouldBeConsumedMoreThanOneTime() throws Exception {
         String input = "mystream";
         Attachment attachment = Attachment.builder()

http://git-wip-us.apache.org/repos/asf/james-project/blob/563a21a6/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentMapper.java
----------------------------------------------------------------------
diff --git 
a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentMapper.java
 
b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentMapper.java
index 5603895..e121cc6 100644
--- 
a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentMapper.java
+++ 
b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentMapper.java
@@ -139,7 +139,7 @@ public class CassandraAttachmentMapper implements 
AttachmentMapper {
         return cassandraAsyncExecutor.executeVoid(
             insertInto(TABLE_NAME)
                 .value(ID, attachment.getAttachmentId().getId())
-                .value(PAYLOAD, 
ByteBuffer.wrap(IOUtils.toByteArray(attachment.getStream())))
+                .value(PAYLOAD, ByteBuffer.wrap(attachment.getBytes()))
                 .value(TYPE, attachment.getType())
                 .value(SIZE, attachment.getSize())
         );


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

Reply via email to