@Override
public BlobURI write(final UUID messageId, final Mailbox mailbox, final String profileName, final InputStream in, final Long size)
throws IOException, GeneralSecurityException
{
String blobName = new BlobNameBuilder().setMailbox(mailbox)
.setMessageId(messageId).setMessageSize(size).build();
InputStream in1;
Long updatedSize = size;
BlobURI blobUri = new BlobURI()
.setProfile(profileName)
.setName(blobName);
if (encryptionHandler != null)
{
byte[] iv = getCipherIVFromBlobName(blobName);
InputStream encryptedInputStream = this.encryptionHandler.encrypt(in, Configurator.getBlobStoreDefaultEncryptionKey(), iv);
FileBackedOutputStream fbout = new FileBackedOutputStream(MAX_MEMORY_FILE_SIZE, true);
updatedSize = ByteStreams.copy(encryptedInputStream, fbout);
in1 = fbout.getSupplier().getInput();
blobUri.setEncryptionKey(Configurator.getBlobStoreDefaultEncryptionKeyAlias());
} else {
in1 = in;
}
CloudStoreProxy.write(blobName, profileName, in1, updatedSize);
return blobUri;
}