aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
authorYuichiro Hanada <yhanada@google.com>2013-08-26 02:12:19 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2013-08-26 02:12:19 -0700
commitbfb4c3aa7fb333d9a62d83a1853e3881b2b06919 (patch)
tree6a346cebadc32f549ffeccce02a58e167e97c642 /java/src
parent71a8b6320b6c7f86d0be0d2c6e875f3dea8c6ea2 (diff)
parentd5a3c593dba3475f5e72b1fbe53cee5ed17a7529 (diff)
downloadlatinime-bfb4c3aa7fb333d9a62d83a1853e3881b2b06919.tar.gz
latinime-bfb4c3aa7fb333d9a62d83a1853e3881b2b06919.tar.xz
latinime-bfb4c3aa7fb333d9a62d83a1853e3881b2b06919.zip
am d5a3c593: Remove a broken dictionary file when fail to read a dictionary file.
* commit 'd5a3c593dba3475f5e72b1fbe53cee5ed17a7529': Remove a broken dictionary file when fail to read a dictionary file.
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderUtils.java3
-rw-r--r--java/src/com/android/inputmethod/latin/makedict/Ver3DictDecoder.java19
2 files changed, 19 insertions, 3 deletions
diff --git a/java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderUtils.java b/java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderUtils.java
index 29f114662..ceb8fa81f 100644
--- a/java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderUtils.java
+++ b/java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderUtils.java
@@ -561,8 +561,7 @@ public final class BinaryDictDecoderUtils {
*/
@UsedForTesting
/* package */ static FusionDictionary readDictionaryBinary(final Ver3DictDecoder dictDecoder,
- final FusionDictionary dict) throws FileNotFoundException, IOException,
- UnsupportedFormatException {
+ final FusionDictionary dict) throws IOException, UnsupportedFormatException {
// Read header
final FileHeader fileHeader = dictDecoder.readHeader();
diff --git a/java/src/com/android/inputmethod/latin/makedict/Ver3DictDecoder.java b/java/src/com/android/inputmethod/latin/makedict/Ver3DictDecoder.java
index 1fff9b49e..1a5023ef6 100644
--- a/java/src/com/android/inputmethod/latin/makedict/Ver3DictDecoder.java
+++ b/java/src/com/android/inputmethod/latin/makedict/Ver3DictDecoder.java
@@ -25,6 +25,8 @@ import com.android.inputmethod.latin.makedict.FusionDictionary.PtNode;
import com.android.inputmethod.latin.makedict.FusionDictionary.WeightedString;
import com.android.inputmethod.latin.utils.JniUtils;
+import android.util.Log;
+
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
@@ -38,6 +40,7 @@ import java.util.TreeMap;
*/
@UsedForTesting
public class Ver3DictDecoder implements DictDecoder {
+ private static final String TAG = Ver3DictDecoder.class.getSimpleName();
static {
JniUtils.loadNativeLibrary();
@@ -308,7 +311,21 @@ public class Ver3DictDecoder implements DictDecoder {
if (mDictBuffer == null) {
openDictBuffer();
}
- return BinaryDictDecoderUtils.readDictionaryBinary(this, dict);
+ try {
+ return BinaryDictDecoderUtils.readDictionaryBinary(this, dict);
+ } catch (IOException e) {
+ Log.e(TAG, "The dictionary " + mDictionaryBinaryFile.getName() + " is broken.", e);
+ if (!mDictionaryBinaryFile.delete()) {
+ Log.e(TAG, "Failed to delete the broken dictionary.");
+ }
+ throw e;
+ } catch (UnsupportedFormatException e) {
+ Log.e(TAG, "The dictionary " + mDictionaryBinaryFile.getName() + " is broken.", e);
+ if (!mDictionaryBinaryFile.delete()) {
+ Log.e(TAG, "Failed to delete the broken dictionary.");
+ }
+ throw e;
+ }
}
@Override