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 2019/07/04 09:29:48 UTC
[james-project] 01/15: Avoid blob copy when saving byte arrays
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 862dd154133317eacffc8e5434083ac0d0452b1d
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Fri Dec 7 14:14:26 2018 +0700
Avoid blob copy when saving byte arrays
We can iterate the in memory byte array first to compute the blobId to use,
saving a blob copy.
---
.../blob/objectstorage/ObjectStorageBlobsDAO.java | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)
diff --git a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/ObjectStorageBlobsDAO.java b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/ObjectStorageBlobsDAO.java
index 7bbd2da..fb22164 100644
--- a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/ObjectStorageBlobsDAO.java
+++ b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/ObjectStorageBlobsDAO.java
@@ -93,8 +93,15 @@ public class ObjectStorageBlobsDAO implements BlobStore {
}
@Override
- public Mono<BlobId> save(BucketName bucketName, byte[] data) {
- return save(bucketName, new ByteArrayInputStream(data));
+ public Mono<BlobId> save(byte[] data) {
+ BlobId blobId = blobIdFactory.forPayload(data);
+
+ Blob blob = blobStore.blobBuilder(blobId.asString())
+ .payload(payloadCodec.write(new ByteArrayInputStream(data)))
+ .build();
+
+ return save(bucketName, blob)
+ .thenApply(any -> blobId);
}
@Override
@@ -121,10 +128,15 @@ public class ObjectStorageBlobsDAO implements BlobStore {
.payload(payload.getPayload())
.build();
- return Mono.fromRunnable(() -> putBlobFunction.putBlob(blob))
+ return save(blob)
.then(Mono.fromCallable(() -> blobIdFactory.from(hashingInputStream.hash().toString())));
}
+ private Mono<String> save(Blob blob) {
+ String containerName = this.containerName.value();
+ return Mono.fromCallable(() -> blobStore.putBlob(containerName, blob));
+ }
+
@Override
public Mono<byte[]> readBytes(BucketName bucketName, BlobId blobId) {
return Mono.fromCallable(() -> IOUtils.toByteArray(read(bucketName, blobId)));
@@ -145,7 +157,6 @@ public class ObjectStorageBlobsDAO implements BlobStore {
"Failed to readBytes blob " + blobId.asString(),
cause);
}
-
}
public void deleteContainer() {
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org