private Mono<Integer> selectRowCount(BlobId blobId) { return cassandraAsyncExecutor.executeSingleRowReactor( select.bind() .setString(BlobTable.ID, blobId.asString())) .map(row -> row.getInt(BlobTable.NUMBER_OF_CHUNK)); }
@Override public InputStream read(BlobId blobId) throws ObjectStoreException { Blob blob = blobStore.getBlob(containerName.value(), blobId.asString()); try { if (blob != null) { return payloadCodec.read(blob.getPayload()); } else { return EMPTY_STREAM; } } catch (IOException cause) { throw new ObjectStoreException( "Failed to readBytes blob " + blobId.asString(), cause); } } }
private Mono<byte[]> readPart(BlobId blobId, int position) { return cassandraAsyncExecutor.executeSingleRowReactor( selectPart.bind() .setString(BlobTable.ID, blobId.asString()) .setInt(BlobParts.CHUNK_NUMBER, position)) .map(this::rowToData) .switchIfEmpty(Mono.error(new IllegalStateException( String.format("Missing blob part for blobId %s and position %d", blobId, position)))); }
private Mono<BlobId> saveBlobPartsReferences(BlobId blobId, int numberOfChunk) { return cassandraAsyncExecutor.executeVoidReactor( insert.bind() .setString(BlobTable.ID, blobId.asString()) .setInt(BlobTable.NUMBER_OF_CHUNK, numberOfChunk)) .then(Mono.just(blobId)); }
@Test public void forPayloadShouldHashArray() { BlobId blobId = BLOB_ID_FACTORY.forPayload("content".getBytes(StandardCharsets.UTF_8)); assertThat(blobId.asString()).isEqualTo("ed7002b439e9ac845f22357d822bac1444730fbdb6016d3ec9432297b9ec9f73"); }
@Test public void forPayloadShouldHashEmptyArray() { BlobId blobId = BLOB_ID_FACTORY.forPayload(new byte[0]); assertThat(blobId.asString()).isEqualTo("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"); }
private Mono<Integer> writePart(ByteBuffer data, BlobId blobId, int position) { return cassandraAsyncExecutor.executeVoidReactor( insertPart.bind() .setString(BlobTable.ID, blobId.asString()) .setInt(BlobParts.CHUNK_NUMBER, position) .setBytes(BlobParts.DATA, data)) .then(Mono.just(position)); }
private BoundStatement boundWriteStatement(MailboxMessage message, Pair<BlobId, BlobId> pair) { CassandraMessageId messageId = (CassandraMessageId) message.getMessageId(); return insert.bind() .setUUID(MESSAGE_ID, messageId.get()) .setTimestamp(INTERNAL_DATE, message.getInternalDate()) .setInt(BODY_START_OCTET, (int) (message.getHeaderOctets())) .setLong(FULL_CONTENT_OCTETS, message.getFullContentOctets()) .setLong(BODY_OCTECTS, message.getBodyOctets()) .setString(BODY_CONTENT, pair.getRight().asString()) .setString(HEADER_CONTENT, pair.getLeft().asString()) .setLong(TEXTUAL_LINE_COUNT, Optional.ofNullable(message.getTextualLineCount()).orElse(DEFAULT_LONG_VALUE)) .setList(PROPERTIES, buildPropertiesUdt(message)) .setList(ATTACHMENTS, buildAttachmentUdt(message)); }
private BlobId save(InputStream data, BlobId id) { String containerName = this.containerName.value(); HashingInputStream hashingInputStream = new HashingInputStream(Hashing.sha256(), data); Payload payload = payloadCodec.write(hashingInputStream); Blob blob = blobStore.blobBuilder(id.asString()).payload(payload).build(); blobStore.putBlob(containerName, blob); return blobIdFactory.from(hashingInputStream.hash().toString()); }
public CompletableFuture<Void> storeAttachment(DAOAttachment attachment) { return cassandraAsyncExecutor.executeVoid( insertStatement.bind() .setUUID(ID_AS_UUID, attachment.getAttachmentId().asUUID()) .setString(ID, attachment.getAttachmentId().getId()) .setLong(SIZE, attachment.getSize()) .setString(TYPE, attachment.getType()) .setString(BLOB_ID, attachment.getBlobId().asString())); }