public static ByteBuffer fetchFrom ( ByteBuffer buf , ReadableByteChannel ch , int size ) throws IOException { ByteBuffer result = buf . duplicate ( ) ; result . limit ( size ) ; NIOUtils . readFromChannel ( ch , result ) ; result . flip ( ) ; return result ; }
Reads size amount of bytes from ch into a new ByteBuffer allocated from a buffer buf