java - Channels.newChanne() will help to achieve actual ZeroCopy -


i have doubt regarding using channels.newchannel(outputstream/inputstream) in zerocopy operation. serve zerocopy. have restriction have send 1st header part(file , user related information) file content. testing, override bufferedoutputstream, on filechannel.transferto call, calling override methods... please me how achieve zerocopy in such circumstances(header+content).

part of testing code:

string host = "127.0.0.1"; socketaddress sad = new inetsocketaddress(host, zerocopyserver.port); socket s=new socket(); s.connect(sad);  outputstream o=s.getoutputstream(); outputstream out=new bufferedoutputstream(o); writablebytechannel ch=channels.newchannel(o); //can use //writablebytechannel ch=channels.newchannel(out);  string msg="hi how , doing..."; out.write(msg.getbytes()); out.flush();  string fname = "hello.txt"; string fname2 = "input"; long filesize = new file(fname).length();  filechannel fc = new fileinputstream(fname).getchannel(); filechannel fc2 = new fileinputstream(fname2).getchannel();  fc.transferto(0, fc.size(), ch); fc2.transferto(0, fc2.size(), ch);  fc.close(); fc2.close(); out.close(); ch.close(); 

will serve zerocopy.

no. have start socketchannel that, not socket, , use directly in transferto().

i have restriction have send 1st header part(file , user related information)

well can't 0 copy.

then file content.

that part can achieve.

note transferto() isn't specified entire transfer in single call. have loop, noting return value , adjusting offset accordingly until it's done.


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -