use of com.mongodb.internal.connection.AsynchronousChannelStream in project mongo-java-driver by mongodb.
the class KeyManagementService method streamRead.
private void streamRead(final Stream stream, final MongoKeyDecryptor keyDecryptor, final MonoSink<Void> sink) {
int bytesNeeded = keyDecryptor.bytesNeeded();
if (bytesNeeded > 0) {
AsynchronousChannelStream asyncStream = (AsynchronousChannelStream) stream;
final ByteBuf buffer = asyncStream.getBuffer(bytesNeeded);
asyncStream.getChannel().read(buffer.asNIO(), asyncStream.getSettings().getReadTimeout(MILLISECONDS), MILLISECONDS, null, new CompletionHandler<Integer, Void>() {
@Override
public void completed(final Integer integer, final Void aVoid) {
buffer.flip();
try {
keyDecryptor.feed(buffer.asNIO());
buffer.release();
streamRead(stream, keyDecryptor, sink);
} catch (Throwable t) {
sink.error(t);
}
}
@Override
public void failed(final Throwable t, final Void aVoid) {
buffer.release();
stream.close();
sink.error(t);
}
});
} else {
stream.close();
sink.success();
}
}
Aggregations