byte[] contentBytes = content.getBytes();
logger.trace("Uploading {} digest {}", content, digestString);
BytesArray bytes = new BytesArray(new byte[]{contentBytes[0]});
if (content.length() == 1) {
client.execute(StartBlobAction.INSTANCE,
new StartBlobRequest(BlobIndices.fullIndexName("test"), digest, bytes,true))
.actionGet();
} else {
StartBlobRequest startBlobRequest = new StartBlobRequest(
BlobIndices.fullIndexName("test"), digest, bytes, false);
client.execute(StartBlobAction.INSTANCE, startBlobRequest).actionGet();
for (int i = 1; i < contentBytes.length; i++) {
try {
Thread.sleep(timeBetweenChunks.get());
} catch (InterruptedException ex) {
Thread.interrupted();
}
bytes = new BytesArray(new byte[]{contentBytes[i]});
client.execute(PutChunkAction.INSTANCE,
new PutChunkRequest(
BlobIndices.fullIndexName("test"), digest,
startBlobRequest.transferId(), bytes, i,
(i + 1) == content.length())
).actionGet();
}
}
logger.trace("Upload finished {} digest {}", content, digestString);