ファイルを送信するときには、ctx.writeAndFlush(new ChunkedFile(new File("file.png")));
とすることができます。リストをチャンクする方法 in Netty
どのように約List<Object>
?
リストには、String
とbytes of image
が含まれています。
文書にはChunkedInput()
がありますが、私はそれを利用することができません。
UPDATE
のは、私はちょうどChunkedInput<ByteBuf>
あなた自身を実装するには、以下の
@Override
protected void channelRead0(ChannelHandlerContext ctx, Object o) throws Exception {
List<Object> msg = new ArrayList<>();
/**getting the bytes of image**/
byte[] imageInByte;
BufferedImage originalImage = ImageIO.read(new File(fileName));
// convert BufferedImage to byte array
ByteArrayOutputStream bAoS = new ByteArrayOutputStream();
ImageIO.write(originalImage, "png", bAoS);
bAoS.flush();
imageInByte = baos.toByteArray();
baos.close();
msg.clear();
msg.add(0, "String"); //add the String into List
msg.add(1, imageInByte); //add the bytes of images into list
/**Chunk the List<Object> and Send it just like the chunked file**/
ctx.writeAndFlush(new ChunkedInput(DONT_KNOW_WHAT_TO_DO_HERE)); //
}
ちょっと注意してください...ファイルを送信し、パイプラインでそのコンテンツを操作する必要がない場合、あなたは 'sendfile(...)'を使用できるように 'DefaultFileRegion'を実際に使うべきです。別名ゼロコピーファイル転送。 –
@ St.Antario - 私の質問にお答えいただきありがとうございます!私は本当にありがとうと私はあなたの答えは私に解決策を与えることができると思う、私は本当に 'ChunkedInput()'の使用を取得しないので、あなたは私のためにもっと明確にしてくださいできますか?ハンドラの中で、 'channelRead0(ChannelHandlerContext ctx、Object o)'の質問を既に更新しています。あなたのソリューションをどのように使うことができますか?どうもありがとうございます! – Polar
@Polarはいくつかの情報を追加しました:) –