I have some doubt regarding using Channels.newChannel(OutputStream/InputStream) in zeroCopy operation. Will it serve as zeroCopy. I have some restriction like have to send 1st header part(file and user related information) then file content. For testing, i also override BufferedOutputStream, but on fileChannel.transferTo call, it is calling my override methods... Please help me how to 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 i use
//WritableByteChannel ch=Channels.newChannel(out);
String msg="Hi how are you and what are you 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();