Change expandable binary dict write to a temp file first.
Bug: 6380724 Change-Id: Ic1d0d902dc45ecb41a1792f33a60ab85e606fcef
This commit is contained in:
parent
7f45ec7bb8
commit
a9b2be8a81
1 changed files with 4 additions and 1 deletions
|
@ -288,13 +288,16 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
||||||
|
|
||||||
loadDictionaryAsync();
|
loadDictionaryAsync();
|
||||||
|
|
||||||
|
final String tempFileName = mFilename + ".temp";
|
||||||
final File file = new File(mContext.getFilesDir(), mFilename);
|
final File file = new File(mContext.getFilesDir(), mFilename);
|
||||||
|
final File tempFile = new File(mContext.getFilesDir(), tempFileName);
|
||||||
FileOutputStream out = null;
|
FileOutputStream out = null;
|
||||||
try {
|
try {
|
||||||
out = new FileOutputStream(file);
|
out = new FileOutputStream(tempFile);
|
||||||
BinaryDictInputOutput.writeDictionaryBinary(out, mFusionDictionary, 1);
|
BinaryDictInputOutput.writeDictionaryBinary(out, mFusionDictionary, 1);
|
||||||
out.flush();
|
out.flush();
|
||||||
out.close();
|
out.close();
|
||||||
|
tempFile.renameTo(file);
|
||||||
clearFusionDictionary();
|
clearFusionDictionary();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.e(TAG, "IO exception while writing file: " + e);
|
Log.e(TAG, "IO exception while writing file: " + e);
|
||||||
|
|
Loading…
Reference in a new issue