/**
   * Reads a primitive value of the specified class type from the stream.
   *
   * @param in A stream to read from.
   * @param cls A class type of the primitive.
   * @return A primitive.
   * @throws IOException If an I/O error occurs.
   */
  static Object readPrimitive(DataInput in, Class cls) throws IOException {
    if (cls == byte.class) return in.readByte();

    if (cls == short.class) return in.readShort();

    if (cls == int.class) return in.readInt();

    if (cls == long.class) return in.readLong();

    if (cls == float.class) return in.readFloat();

    if (cls == double.class) return in.readDouble();

    if (cls == boolean.class) return in.readBoolean();

    if (cls == char.class) return in.readChar();

    throw new IllegalArgumentException();
  }