public static int readAll(InputStream i,byte b[]) throws IOException {
  int len=b.length;
  int n=0;
  while (n < len) {
    int count=i.read(b,n,len - n);
    if (count < 0) {
      return n;
    }
    n+=count;
  }
  return n;
}

public static int readAll ( InputStream i , byte b [ ] ) throws IOException { int len = b . length ; int n = 0 ; while ( n < len ) { int count = i . read ( b , n , len - n ) ; if ( count < 0 ) { return n ; } n += count ; } return n ; }
reads until the array is full or until the stream ends
