@NonNull
    public FileOutputStream startWrite() throws IOException {
        // Rename the current file so it may be used as a backup during the next read
        if (mBaseName.exists()) {
            if (!mBackupName.exists()) {
                if (!mBaseName.renameTo(mBackupName)) {
                    Log.w("AtomicFile", "Couldn't rename file " + mBaseName
                            + " to backup file " + mBackupName);
                }
            } else {
                mBaseName.delete();
            }
        }
        FileOutputStream str;
        try {
            str = new FileOutputStream(mBaseName);
        } catch (FileNotFoundException e) {
            File parent = mBaseName.getParentFile();
            if (!parent.mkdirs()) {
                throw new IOException("Couldn't create directory " + mBaseName);
            }
            try {
                str = new FileOutputStream(mBaseName);
            } catch (FileNotFoundException e2) {
                throw new IOException("Couldn't create " + mBaseName);
            }
        }
        return str;
    }
Start a new write operation on the file.  This returns a FileOutputStream
to which you can write the new file data.  The existing file is replaced
with the new data.  You <em>must not</em> directly close the given
FileOutputStream; instead call either {@link #finishWrite(FileOutputStream)}
or {@link #failWrite(FileOutputStream)}.

<p>Note that if another thread is currently performing
a write, this will simply replace whatever that thread is writing
with the new file being written by this thread, and when the other
thread finishes the write the new write operation will no longer be
safe (or will be lost).  You must do your own threading protection for
access to AtomicFile.
android/android_framework/base/src/main/java/github/tornaco/android/thanos/core/util/AtomicFile.java