私はこの機能をUnpooled Nettyバッファを使って実現できました。 3.10以降のNettyを使用している場合、Poolクラスの代わりにChannelBuffersを使用することができます。 In Netty 4.0/4.1 ChannelBuffersはUnpooledに置き換えられました。以下は
はサンプルコードです:
import io.netty.buffer.Unpooled;
import java.nio.file.Files;
import java.nio.file.Paths;
response.setContentType("application/pdf"); //Setting content type to be pdf
response.addHeader("Content-disposition", "attachment; filename=" + outputFileAddress);
LOG.info(outputFileAddress);
java.nio.file.Path path = Paths.get(outputFileAddress);
byte[] data = Files.readAllBytes(path);
response.setBody(Unpooled.wrappedBuffer(data));
response.noSerialization(); // No serialization avoids getting the stream to Jackson
response.setResponseStatus(HttpResponseStatus.OK);