code: @Override
      public Element readElement(final int index) throws IOException {
          if (index < 0) {
              throw new IndexOutOfBoundsException("Index is negative.");
          }
          if (closed) {
              throw new IllegalStateException("Reader is closed.");
          }
          while (index >= buffer.size()) {
              Element element = reader.readElement();
              if (element == null) {
                  throw new IndexOutOfBoundsException(
                          "Index is larger or equal to the number of elements.");
              } else {
                  buffer.add(element);
              }
          }
          return buffer.get(index);
      }
docs: Reads an element at a specific position.
  <p>This method does not influence the order in which the elements
  are read by {@link #readElement()}.</p>
  <p>The execution time of this method can be in the order of
  {@code O(index)} in the worst case. On average its {@code O(1)}.</p>
  @param index Zero-bound index of the element to read.
  @return Element at the given index.
  @throws IOException if reading fails.
  @throws IndexOutOfBoundsException if the index is out of range (negative
  or greater-equal to the number of elements).