question: private static int readFully ( InputStream in , byte [ ] buffer , int max ) throws IOException { int result = 0 , len = Math . min ( max , buffer . length ) ; while ( len > 0 ) { int l = in . read ( buffer , result , len ) ; if ( l < 0 ) { break ; } result += l ; len -= l ; } return result ; }
target:  Read a number of bytes. This method repeats reading until either the bytes have been read, or EOF.