Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
private void loadFromDiskLocked() {
//(snip)
if (mBackupFile.exists()) {
mFile.delete();
mBackupFile.renameTo(mFile);
}
//(snip)
if (FileUtils.getFileStatus(mFile.getPath(), stat) && mFile.canRead()) {
//(snip) ここでファイルから読み込む
}
//(snip)
}
// Note: must hold mWritingToDiskLock
private void writeToFile(MemoryCommitResult mcr) {
// Rename the current file so it may be used as a backup during the next read
if (mFile.exists()) {
//(snip)
if (!mBackupFile.exists()) {
if (!mFile.renameTo(mBackupFile)) {
Log.e(TAG, "Couldn't rename file " + mFile
+ " to backup file " + mBackupFile);
mcr.setDiskWriteResult(false);
return;
}
} else {
mFile.delete();
}
}
// Attempt to write the file, delete the backup and return true as atomically as
// possible. If any exception occurs, delete the new file; next time we will restore
// from the backup.
try {
FileOutputStream str = createFileOutputStream(mFile);
//(snip)
// Writing was successful, delete the backup file if there is one.
mBackupFile.delete();
//(snip)
return;
} catch (XmlPullParserException e) {
Log.w(TAG, "writeToFile: Got exception:", e);
} catch (IOException e) {
Log.w(TAG, "writeToFile: Got exception:", e);
}
// Clean up an unsuccessfully written file
if (mFile.exists()) {
if (!mFile.delete()) {
Log.e(TAG, "Couldn't clean up partially-written file " + mFile);
}
}
//(snip)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.