http - How to read from CompositeChannelBuffer? -
during testing, loading jpg image browser netty based littleproxy sitting between server , client. while loading particular image. channel buffer of compositchannelbuffer. reading following way, not working.
if (chanbuff instanceof compositechannelbuffer) { compositechannelbuffer compchanbuf = ((compositechannelbuffer) chanbuff); int noofcomps = compchanbuf.numcomponents(); list<channelbuffer> bufflist = compchanbuf.decompose(0, noofcomps); listiterator<channelbuffer> itr = bufflist.listiterator(); int offset = 0; int bytesread = -1; while (itr.hasnext()) { channelbuffer buf = (channelbuffer) itr.next(); bytesread = buf.array().length; outputstream.write(buf.array(), offset, bytesread); offset += bytesread; } } i tried below code, not able write file.
if (chanbuff instanceof compositechannelbuffer){ fileoutputstream outputstream = new fileoutputstream(outputfilename); compositechannelbuffer compchanbuf = ((compositechannelbuffer) chanbuff); int noofcomps = compchanbuf.numcomponents(); compchanbuf.getbytes(0, outputstream, noofcomps); channelbuffer dynamicbuf = dynamicbuffer(); compchanbuf.getbytes(0, dynamicbuf); array = dynamicbuf.array(); outputstream.write(array); } what correct way read compositchannelbuffer?
just other buffers like:
channelbuffer buf = ... outputstream out = ... buf.getbytes(0, out, buf.readablebytes());
Comments
Post a Comment