public static ByteBuffer readFile ( File inFile ) throws IOException { ByteBuffer mBuf ; try ( FileInputStream fIn = new FileInputStream ( inFile ) ; FileChannel fChan = fIn . getChannel ( ) ) { long fSize = fChan . size ( ) ; mBuf = ByteBuffer . allocate ( ( int ) fSize ) ; fChan . read ( mBuf ) ; mBuf . rewind ( ) ; } return mBuf ; }
Helper method to read a file into a ByteBuffer