public static ByteBuffer fill ( ReadableByteChannel in , ByteBuffer buffer ) throws IOException { while ( buffer . hasRemaining ( ) ) if ( in . read ( buffer ) == - 1 ) throw new BufferUnderflowException ( ) ; buffer . flip ( ) ; return buffer ; }
Fills the provided buffer it with bytes from the provided channel . The amount of data to read is dependant on the available space in the provided buffer .