code: private void writeHeader(long fileLength, int elementCount, long firstPosition, long lastPosition)
        throws IOException {
      raf.seek(0);
  
      if (versioned) {
        writeInt(buffer, 0, VERSIONED_HEADER);
        writeLong(buffer, 4, fileLength);
        writeInt(buffer, 12, elementCount);
        writeLong(buffer, 16, firstPosition);
        writeLong(buffer, 24, lastPosition);
        raf.write(buffer, 0, 32);
        return;
      }
  
      // Legacy queue header.
      writeInt(buffer, 0, (int) fileLength); // Signed, so leading bit is always 0 aka legacy.
      writeInt(buffer, 4, elementCount);
      writeInt(buffer, 8, (int) firstPosition);
      writeInt(buffer, 12, (int) lastPosition);
      raf.write(buffer, 0, 16);
    }
docs: Writes header atomically. The arguments contain the updated values. The class member fields
  should not have changed yet. This only updates the state in the file. It's up to the caller to
  update the class member variables *after* this call succeeds. Assumes segment writes are
  atomic in the underlying file system.