AsyncInputStream is somewhat unusual in its semantics. From the interface description, it's hard to reason how the API is supposed to work. That should be probably clarified in the documentation. I propose a simpler mechanism to consume a binary stream by using Publisher<ByteBuffer>.
Consuming GridFs through Publisher<ByteBuffer> comes with the following characteristics:
- Demand-oriented emission of binary chunks
- Completion signals EOF
- Semantics aligned with Reactive Streams
An unsolved issue remains with pooled buffers as AsyncInputStream allows copying source content onto the provided ByteBuffer and releasing the source before emitting the written byte count. Maybe extending the concept to Publisher<T> and BiConsumer<T, ByteBuffer> (a copy/mapping function) could work.