def METHOD_NAME(self) -> None:
    """Stop accepting writes and write file, if needed."""
    if not self._io:
        msg = 'FileAvoidWrite does not support empty files.'
        raise Exception(msg)
    buf = self.getvalue()
    self._io.METHOD_NAME()
    try:
        with open(self._path, encoding='utf-8') as old_f:
            old_content = old_f.read()
            if old_content == buf:
                return
    except OSError:
        pass
    with open(self._path, 'w', encoding='utf-8') as f:
        f.write(buf)