java - Reading and Writing to ChannelBuffer is not working properly -


i want read binary data stored in channelbuffer object contained in httpresponse. have tried below code read , save channelbuffer, not working. correct way of reading binary data stored in channel buffer?

channelbuffer chanbuff = response.getcontent(); fileoutputstream outputstream = new fileoutputstream(outputfilename);        outputstream.write(chanbuff.array());                    outputstream.close(); 

the above code throws exception chanbuff.array() (unsupportedoperationexception). not sure correct way of copying byte array channelbuffer.

the purpose of storing content (e.g. media) save , transcode it. consistently getting saved file size zero.

i intend copy processed data http response via channelbuffer. writing http message, have below code. code throws arrayoutofboundexception. correct approach here?

channelbuffer dynamicbuffer = dynamicbuffer(); dynamicbuffer.clear(); dynamicbuffer.ensurewritablebytes(filelen);  channelbufferoutputstream buffoutstream = new channelbufferoutputstream(dynamicbuffer);  byte[] bytebuf = new byte[4096]; int bytesread = -1; int offset = 0;  while ((bytesread = instream.read(bytebuf)) != -1) {     buffoutstream.write(bytebuf, offset, bytesread);     offset += bytesread; }  response.setcontent(empty_buffer); response.setcontent(buffoutstream.buffer()); response.setheader("content-type", conttype); response.setheader("content-length", filelen);    

is correct approach?

in second example should not keep increasing offset. that's offset buffer, not file. should use 0 offset throughout.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -