Skip to content

Instantly share code, notes, and snippets.

View cyberdelia's full-sized avatar

Timothée Peignier cyberdelia

View GitHub Profile
@iconara
iconara / InputStreamResponseTransformer.java
Last active November 5, 2020 16:51
S3 GetObject InputStreamResponseTransformer using AWS SDK for Java v2
// this is an attempt to create a synchronous InputStream from a call to
// S3AsyncClient#getObject using a blocking queue.
//
// the purpose is to be able to make many S3 operations asynchronously, but
// at the same time be able to pass off some results to threads and into
// code that expects InputStream or Reader, like a Commons CSV.
public class InputStreamResponseTransformer extends InputStream implements AsyncResponseTransformer<GetObjectResponse, InputStream>, Subscriber<ByteBuffer> {
private static final ByteBuffer END_MARKER = ByteBuffer.allocate(0);