use of org.apache.ratis.statemachine.StateMachine.DataChannel in project incubator-ratis by apache.
the class DataStreamManagement method writeTo.
static long writeTo(ByteBuf buf, WriteOption[] options, DataStream stream) {
final DataChannel channel = stream.getDataChannel();
long byteWritten = 0;
for (ByteBuffer buffer : buf.nioBuffers()) {
try {
byteWritten += channel.write(buffer);
} catch (Throwable t) {
throw new CompletionException(t);
}
}
if (WriteOption.containsOption(options, StandardWriteOption.SYNC)) {
try {
channel.force(false);
} catch (IOException e) {
throw new CompletionException(e);
}
}
if (WriteOption.containsOption(options, StandardWriteOption.CLOSE)) {
close(stream);
}
return byteWritten;
}
Aggregations