【发布时间】:2017-12-13 13:48:32
【问题描述】:
发送文件时可以ctx.writeAndFlush(new ChunkedFile(new File("file.png")));。
List<Object> 怎么样?
该列表包含String 和bytes of image。
从文档中有ChunkedInput(),但我无法使用它。
更新
假设在我的处理程序中,在我想要发送 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)); //
}
【问题讨论】:
标签: java netty netty-socketio