You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by ad...@apache.org on 2017/07/25 07:29:30 UTC
[1/2] james-project git commit: JAMES-2095 optimize IO on
storeAttachments
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 <ld...@linagora.com>
Authored: Mon Jul 10 14:16:46 2017 +0200
Committer: Antoine Duprat <ad...@linagora.com>
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: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[2/2] james-project git commit: JAMES-2095 AttachmentTest: specify
charset for string/byte conv
Posted by ad...@apache.org.
JAMES-2095 AttachmentTest: specify charset for string/byte conv
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/0a8c8501
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/0a8c8501
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/0a8c8501
Branch: refs/heads/master
Commit: 0a8c8501139953247663a728c2626b1ca89d99eb
Parents: 563a21a
Author: Luc DUZAN <ld...@linagora.com>
Authored: Mon Jul 10 17:26:55 2017 +0200
Committer: Antoine Duprat <ad...@linagora.com>
Committed: Tue Jul 25 09:28:22 2017 +0200
----------------------------------------------------------------------
.../james/mailbox/model/AttachmentTest.java | 28 +++++++++++---------
1 file changed, 16 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/0a8c8501/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 53728eb..8edbdae 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
@@ -23,7 +23,9 @@ package org.apache.james.mailbox.model;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.InputStream;
+import java.nio.charset.Charset;
+import com.google.common.base.Charsets;
import org.apache.commons.io.IOUtils;
import org.apache.james.mailbox.model.Attachment;
@@ -31,43 +33,45 @@ import org.junit.Test;
public class AttachmentTest {
+ private static Charset CHARSET = Charsets.UTF_8;
+
@Test
public void streamShouldBeConsumedOneTime() throws Exception {
String input = "mystream";
Attachment attachment = Attachment.builder()
- .bytes(input.getBytes())
+ .bytes(input.getBytes(CHARSET))
.type("content")
.build();
InputStream stream = attachment.getStream();
assertThat(stream).isNotNull();
- assertThat(IOUtils.toString(stream)).isEqualTo(input);
+ assertThat(IOUtils.toString(stream, CHARSET)).isEqualTo(input);
}
@Test
public void getByteShouldReturnByteArrayRepresentingTheAttachment() throws Exception {
String input = "mystream";
Attachment attachment = Attachment.builder()
- .bytes(input.getBytes())
+ .bytes(input.getBytes(CHARSET))
.type("content")
.build();
byte[] bytes = attachment.getBytes();
- assertThat(new String(bytes)).isEqualTo(input);
+ assertThat(new String(bytes, CHARSET)).isEqualTo(input);
}
@Test
public void streamShouldBeConsumedMoreThanOneTime() throws Exception {
String input = "mystream";
Attachment attachment = Attachment.builder()
- .bytes(input.getBytes())
+ .bytes(input.getBytes(CHARSET))
.type("content")
.build();
attachment.getStream();
InputStream stream = attachment.getStream();
assertThat(stream).isNotNull();
- assertThat(IOUtils.toString(stream)).isEqualTo(input);
+ assertThat(IOUtils.toString(stream, CHARSET)).isEqualTo(input);
}
@Test (expected = IllegalArgumentException.class)
@@ -102,21 +106,21 @@ public class AttachmentTest {
@Test (expected = IllegalStateException.class)
public void buildShouldThrowWhenBytesIsNotProvided() {
Attachment.builder()
- .attachmentId(AttachmentId.forPayload("mystream".getBytes()))
+ .attachmentId(AttachmentId.forPayload("mystream".getBytes(CHARSET)))
.build();
}
@Test (expected = IllegalStateException.class)
public void buildShouldThrowWhenTypeIsNotProvided() {
Attachment.builder()
- .attachmentId(AttachmentId.forPayload("mystream".getBytes()))
- .bytes("mystream".getBytes())
+ .attachmentId(AttachmentId.forPayload("mystream".getBytes(CHARSET)))
+ .bytes("mystream".getBytes(CHARSET))
.build();
}
@Test
public void buildShouldSetTheAttachmentId() throws Exception {
- byte[] bytes = "mystream".getBytes();
+ byte[] bytes = "mystream".getBytes(CHARSET);
Attachment attachment = Attachment.builder()
.bytes(bytes)
.type("content")
@@ -130,10 +134,10 @@ public class AttachmentTest {
public void buildShouldSetTheSize() throws Exception {
String input = "mystream";
Attachment attachment = Attachment.builder()
- .bytes(input.getBytes())
+ .bytes(input.getBytes(CHARSET))
.type("content")
.build();
- assertThat(attachment.getSize()).isEqualTo(input.getBytes().length);
+ assertThat(attachment.getSize()).isEqualTo(input.getBytes(CHARSET).length);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org