in onDataAvailable I have to check:
else if stream.isFinished()
onAllDataRead() // call onAllDataRead manually because it's missed in most cases
For reference this is often running asynchronously, off the IO thread in most cases. The use case is a ReadListener implementation that writes data to an AsynchronousFileChannel.