code: protected int readFully(InputStream in, byte buffer[], int offset, int len)
          throws java.io.IOException {
          for (int i = 0; i < len; i++) {
              int q = in.read();
              if (q == -1)
                  return ((i == 0) ? -1 : i);
              buffer[i+offset] = (byte)q;
          }
          return len;
      }
docs: This method works around the bizarre semantics of BufferedInputStream's
  read method.