파일을 보낼 때 ctx.writeAndFlush(new ChunkedFile(new File("file.png")));
을 사용할 수 있습니다.청크 작성 방법 <Object> in Netty
어때 약 List<Object>
?
목록에 String
및 bytes of image
이 포함되어 있습니다.
설명서에는 ChunkedInput()
이 있지만 사용법을 알 수는 없습니다.
UPDATE
은 내가 수행 한 List<Object>
를 보낼 위치의이 channelRead0(ChannelHandlerContext ctx, Object o)
방법 안에, 내 처리기에서 말을하자
@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)); //
}
단지 참고 사항 ... 파일을 보내고 파이프 라인에서 내용을 조작 할 필요가 없다면'DefaultFileRegion'을 사용해야합니다. 왜냐하면'sendfile (...) '을 사용할 수 있기 때문입니다. 일컬어 제로 카피 파일 전송. –
@ St.Antario - 내 질문에 답변 해 주셔서 감사합니다! 정말 고맙습니다. 당신의 답이 저에게 해결책을 줄 수 있다고 생각합니다. 정말 ChunkedInput()을 사용하지 않습니다. 제게 좀 더 명확하게 해주시겠습니까? 내 처리기 내에서'channelRead0 (ChannelHandlerContext ctx, Object o) '에 내 질문을 이미 업데이트했습니다. 어떻게 주어진 솔루션을 사용할 수 있습니까? 정말 고맙습니다! – Polar
@Polar는 약간의 정보를 추가했습니다 :) –