Created
April 7, 2012 15:22
-
-
Save tateisu/2329685 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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