code: public static void readFully(InputStream in, byte [] buf, int off, int len)
          throws IOException {
          int n = 0;
          while (n < len) {
              int count = in.read(buf, off + n, len - n);
              if (count < 0)
                  throw new EOFException();
              n += count;
          }
      }
docs: Reads some number of bytes from the input stream.
  This function blocks until all data is read or an I/O
  error occurs.
  
  @param in the input stream to read the bytes from.
  @param buf the buffer into which read the data is read.
  @param off the start offset in array b at which the data is written.
  @param len the maximum number of bytes to read.
  @exception IOException if I/O error occurs.