I need to get the size in bytes of an InputStream without creating a File instance. Is there any way to do it using Java NIO?
It isn't knowable in principle (consider a peer that never stops writing), and you don't need it. Just read and write in a loop using a fixed size buffer. NIO doesn't offer any magical solution.