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;
}

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 ; }
read a number of bytes . this method repeats reading until either the bytes have been read , or eof .
