use of reactor.ipc.netty.channel.data.FileChunkedStrategy in project reactor-netty by reactor.
the class NettyOutbound method sendFileChunked.
default NettyOutbound sendFileChunked(Path file, long position, long count) {
Objects.requireNonNull(file);
final FileChunkedStrategy strategy = getFileChunkedStrategy();
final boolean needChunkedWriteHandler = context().channel().pipeline().get(NettyPipeline.ChunkedWriter) == null;
if (needChunkedWriteHandler) {
strategy.preparePipeline(context());
}
return then(Mono.using(() -> FileChannel.open(file, StandardOpenOption.READ), fc -> {
try {
ChunkedInput<?> message = strategy.chunkFile(fc);
return FutureMono.from(context().channel().writeAndFlush(message));
} catch (Exception e) {
return Mono.error(e);
}
}, fc -> {
try {
fc.close();
} catch (IOException ioe) {
/*IGNORE*/
} finally {
strategy.cleanupPipeline(context());
}
}));
}
Aggregations