Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added AsyncResponseTransformer.toBlockingInputStream. #3562

Merged
merged 3 commits into from
Nov 23, 2022

Conversation

millems
Copy link
Contributor

@millems millems commented Nov 23, 2022

This allows streaming operation responses to be read as if they're an InputStream.

Example usage:

CompletableFuture<ResponseInputStream<GetObjectResponse>> responseFuture =
    s3AsyncClient.getObject(getObjectRequest, AsyncResponseTransformer.toBlockingInputStream());
try (ResponseInputStream<GetObjectResponse> responseStream = responseFuture.join()) {
    responseStream.transferTo(System.out); // BLOCKS the calling thread
}

Other changes made to support this change:

  1. Created InputStreamSubscriber, a Subscriber<ByteBuffer> that extends InputStream. It allows subscribing to a publisher and then performing blocking reads against it. This is used by AsyncResponseTransformer.
  2. Updated ByteBufferStoringSubscriber to support blockingTransferTo(ByteBuffer). It's like transferTo(ByteBuffer), except that it will block the caller until at least one byte of data is available to be read. This is used by InputStreamSubscriber.
  3. Allow ResponseInputStream to store non-abortable streams. This is used by AsyncResponseTransformer.

@millems millems requested a review from a team as a code owner November 23, 2022 00:23
…ing operation responses to be read as if they're an InputStream.
@millems millems force-pushed the millem/async-response-blocking branch from bae2a7d to 52a6127 Compare November 23, 2022 00:31
@sonarcloud
Copy link

sonarcloud bot commented Nov 23, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 32 Code Smells

90.1% 90.1% Coverage
0.0% 0.0% Duplication

@millems millems merged commit 70929c3 into master Nov 23, 2022
@millems millems deleted the millem/async-response-blocking branch November 23, 2022 21:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants