@Override public CompletableFuture<byte[]> readBytes(BlobId blobId) { return metricFactory .runPublishingTimerMetric(READ_BYTES_TIMER_NAME, blobStoreImpl.readBytes(blobId)); }
private CompletionStage<Optional<Attachment>> retrievePayload(Optional<DAOAttachment> daoAttachmentOptional) { if (!daoAttachmentOptional.isPresent()) { return CompletableFuture.completedFuture(Optional.empty()); } DAOAttachment daoAttachment = daoAttachmentOptional.get(); return blobStore.readBytes(daoAttachment.getBlobId()) .thenApply(bytes -> Optional.of(daoAttachment.toAttachment(bytes))); }
@Override public CompletableFuture<T> read(I blobIds) { CompletableFuture<Stream<Pair<BlobType, byte[]>>> binaries = FluentFutureStream.of(blobIds.asMap() .entrySet() .stream() .map(entry -> blobStore.readBytes(entry.getValue()) .thenApply(bytes -> Pair.of(entry.getKey(), bytes)))) .completableFuture(); return binaries.thenApply(decoder::decode); } }
@Override public CompletableFuture<T> read(I blobIds) { CompletableFuture<Stream<Pair<BlobType, byte[]>>> binaries = FluentFutureStream.of(blobIds.asMap() .entrySet() .stream() .map(entry -> blobStore.readBytes(entry.getValue()) .thenApply(bytes -> Pair.of(entry.getKey(), bytes)))) .completableFuture(); return binaries.thenApply(decoder::decode); } }
private CompletableFuture<byte[]> getFieldContent(String field, Row row) { return blobStore.readBytes(blobIdFactory.from(row.getString(field))); }
@Test void readBytesShouldReturnSplitSavedDataByChunk() { String longString = Strings.repeat("0123456789\n", MULTIPLE_CHUNK_SIZE); BlobId blobId = testee.save(longString.getBytes(StandardCharsets.UTF_8)).join(); byte[] bytes = testee.readBytes(blobId).join(); assertThat(new String(bytes, StandardCharsets.UTF_8)).isEqualTo(longString); }
@Test default void saveShouldSaveEmptyInputStream() { BlobId blobId = testee().save(new ByteArrayInputStream(EMPTY_BYTEARRAY)).join(); byte[] bytes = testee().readBytes(blobId).join(); assertThat(new String(bytes, StandardCharsets.UTF_8)).isEmpty(); }
@Test default void saveShouldSaveEmptyData() { BlobId blobId = testee().save(EMPTY_BYTEARRAY).join(); byte[] bytes = testee().readBytes(blobId).join(); assertThat(new String(bytes, StandardCharsets.UTF_8)).isEmpty(); }
@Test default void readBytesShouldReturnSavedData() { BlobId blobId = testee().save(SHORT_BYTEARRAY).join(); byte[] bytes = testee().readBytes(blobId).join(); assertThat(bytes).isEqualTo(SHORT_BYTEARRAY); }
@Test default void readBytesShouldReturnBigSavedData() { BlobId blobId = testee().save(TWELVE_MEGABYTES).join(); byte[] bytes = testee().readBytes(blobId).join(); assertThat(bytes).isEqualTo(TWELVE_MEGABYTES); }
@Test default void readBytesShouldReturnLongSavedData() { BlobId blobId = testee().save(ELEVEN_KILOBYTES).join(); byte[] bytes = testee().readBytes(blobId).join(); assertThat(bytes).isEqualTo(ELEVEN_KILOBYTES); }
@Test default void readBytesShouldThrowWhenNoExisting() { assertThatThrownBy(() -> testee().readBytes(blobIdFactory().from("unknown")).join()) .hasCauseInstanceOf(ObjectStoreException.class); }
BlobId bodyBlobId = parts.getBodyBlobId(); softly.assertThat(new String(blobStore.readBytes(headerBlobId).join(), StandardCharsets.UTF_8)) .isEqualTo("Date: Thu, 6 Sep 2018 13:29:13 +0700 (ICT)\r\n" + "From: any@any.com\r\n" + "Content-Type: text/plain; charset=UTF-8\r\n" + "Content-Transfer-Encoding: 7bit\r\n\r\n"); softly.assertThat(new String(blobStore.readBytes(bodyBlobId).join(), StandardCharsets.UTF_8)) .isEqualTo("Important mail content"); });