private void writeElectionStateToFile(final File stateFile, QuorumStateData state, short version) {
        if (version > HIGHEST_SUPPORTED_VERSION) {
            throw new IllegalArgumentException(
                String.format(
                    "Quorum state data version (%d) is greater than the supported version (%d)",
                    version,
                    HIGHEST_SUPPORTED_VERSION
                )
            );
        }
        final File temp = new File(stateFile.getAbsolutePath() + ".tmp");
        deleteFileIfExists(temp);

        log.trace("Writing tmp quorum state {}", temp.getAbsolutePath());

        try {
            try (final FileOutputStream fileOutputStream = new FileOutputStream(temp);
                 final BufferedWriter writer = new BufferedWriter(
                     new OutputStreamWriter(fileOutputStream, StandardCharsets.UTF_8)
                 )
            ) {
                ObjectNode jsonState = (ObjectNode) QuorumStateDataJsonConverter.write(state, version);
                jsonState.set(DATA_VERSION, new ShortNode(version));
                writer.write(jsonState.toString());
                writer.flush();
                fileOutputStream.getFD().sync();
            }
            Utils.atomicMoveWithFallback(temp.toPath(), stateFile.toPath());
        } catch (IOException e) {
            throw new UncheckedIOException(
                String.format(
                    "Error while writing the Quorum status from the file %s",
                    stateFile.getAbsolutePath()
                ),
                e
            );
        } finally {
            // cleanup the temp file when the write finishes (either success or fail).
            deleteFileIfExists(temp);
        }
    }
Reads the election state from local file.
raft/src/main/java/org/apache/kafka/raft/FileQuorumStateStore.java