code: public synchronized void remove(int n) throws IOException {
      if (isEmpty()) {
        throw new NoSuchElementException();
      }
      if (n < 0) {
        throw new IllegalArgumentException("Cannot remove negative (" + n + ") number of elements.");
      }
      if (n == 0) {
        return;
      }
      if (n == elementCount) {
        clear();
        return;
      }
      if (n > elementCount) {
        throw new IllegalArgumentException(
            "Cannot remove more elements (" + n + ") than present in queue (" + elementCount + ").");
      }
  
      final int eraseStartPosition = first.position;
      int eraseTotalLength = 0;
  
      // Read the position and length of the new first element.
      int newFirstPosition = first.position;
      int newFirstLength = first.length;
      for (int i = 0; i < n; i++) {
        eraseTotalLength += Element.HEADER_LENGTH + newFirstLength;
        newFirstPosition = wrapPosition(newFirstPosition + Element.HEADER_LENGTH + newFirstLength);
        ringRead(newFirstPosition, buffer, 0, Element.HEADER_LENGTH);
        newFirstLength = readInt(buffer, 0);
      }
  
      // Commit the header.
      writeHeader(fileLength, elementCount - n, newFirstPosition, last.position);
      elementCount -= n;
      first = new Element(newFirstPosition, newFirstLength);
  
      // Commit the erase.
      ringErase(eraseStartPosition, eraseTotalLength);
    }
docs: Removes the eldest {@code n} elements.
  
  @throws NoSuchElementException if the queue is empty