When sending a file you can do ctx.writeAndFlush(new ChunkedFile(new File("file.png")));.
What about List<Object>?
The list contains Stringand bytes of image.
from the documentation there ChunkedInput(), but I can’t use it.
UPDATE
let's say in my handler, inside the method channelRead0(ChannelHandlerContext ctx, Object o)where I want to send List<Object>, I did the following
@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)); //
}
Polar source
share