docs: private static int readFully(InputStream in, byte[] b, int off, int len) throws IOException {
          int total = 0;
          for (;;) {
              int got = in.read(b, off + total, len - total);
              if (got < 0) {
                  return (total == 0) ? -1 : total;
              }
              else {
                  total += got;
                  if (total == len)
                      return total;
              }
          }
      }