diff --git a/java/src/com/android/inputmethod/latin/makedict/FormatSpec.java b/java/src/com/android/inputmethod/latin/makedict/FormatSpec.java index f85431ee8..555c71b4c 100644 --- a/java/src/com/android/inputmethod/latin/makedict/FormatSpec.java +++ b/java/src/com/android/inputmethod/latin/makedict/FormatSpec.java @@ -379,6 +379,15 @@ public final class FormatSpec { mHeaderSize = headerSize; mDictionaryOptions = dictionaryOptions; mFormatOptions = formatOptions; + if (null == getLocaleString()) { + throw new RuntimeException("Cannot create a FileHeader without a locale"); + } + if (null == getVersion()) { + throw new RuntimeException("Cannot create a FileHeader without a version"); + } + if (null == getId()) { + throw new RuntimeException("Cannot create a FileHeader without an ID"); + } } // Helper method to get the locale as a String diff --git a/java/src/com/android/inputmethod/latin/makedict/Ver4DictUpdater.java b/java/src/com/android/inputmethod/latin/makedict/Ver4DictUpdater.java index 883709f83..91d9cf345 100644 --- a/java/src/com/android/inputmethod/latin/makedict/Ver4DictUpdater.java +++ b/java/src/com/android/inputmethod/latin/makedict/Ver4DictUpdater.java @@ -140,8 +140,10 @@ public class Ver4DictUpdater extends Ver4DictDecoder implements DictUpdater { @Override public void deleteWord(final String word) throws IOException, UnsupportedFormatException { - if (mDictBuffer == null) openDictBuffer(); - readHeader(); + if (mDictBuffer == null) { + openDictBuffer(); + readHeader(); + } final int wordPos = getTerminalPosition(word); if (wordPos != FormatSpec.NOT_VALID_WORD) { mDictBuffer.position(wordPos); diff --git a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java index c4749df82..05de37d4c 100644 --- a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java +++ b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java @@ -265,7 +265,7 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase { getContext().getCacheDir()); final FusionDictionary dict = new FusionDictionary(new PtNodeArray(), - BinaryDictUtils.getDictionaryOptions(dictName, dictVersion)); + BinaryDictUtils.makeDictionaryOptions(dictName, dictVersion)); addUnigrams(words.size(), dict, words, shortcuts); addBigrams(dict, words, bigrams); checkDictionary(dict, words, bigrams, shortcuts); @@ -444,7 +444,7 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase { // making the dictionary from lists of words. final FusionDictionary dict = new FusionDictionary(new PtNodeArray(), - BinaryDictUtils.getDictionaryOptions(dictName, dictVersion)); + BinaryDictUtils.makeDictionaryOptions(dictName, dictVersion)); addUnigrams(words.size(), dict, words, null /* shortcutMap */); addBigrams(dict, words, bigrams); @@ -555,7 +555,7 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase { getContext().getCacheDir()); final FusionDictionary dict = new FusionDictionary(new PtNodeArray(), - BinaryDictUtils.getDictionaryOptions(dictName, dictVersion)); + BinaryDictUtils.makeDictionaryOptions(dictName, dictVersion)); addUnigrams(sWords.size(), dict, sWords, null /* shortcutMap */); addBigrams(dict, words, bigrams); timeWritingDictToFile(file, dict, formatOptions); @@ -649,8 +649,7 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase { getContext().getCacheDir()); final FusionDictionary dict = new FusionDictionary(new PtNodeArray(), - new FusionDictionary.DictionaryOptions( - new HashMap(), false, false)); + BinaryDictUtils.makeDictionaryOptions(dictName, dictVersion)); addUnigrams(sWords.size(), dict, sWords, null /* shortcutMap */); timeWritingDictToFile(file, dict, formatOptions); diff --git a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtilsTests.java b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtilsTests.java index 8bea3c074..da217cea6 100644 --- a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtilsTests.java +++ b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtilsTests.java @@ -233,7 +233,7 @@ public class BinaryDictIOUtilsTests extends AndroidTestCase { // set an initial dictionary. final FusionDictionary dict = new FusionDictionary(new PtNodeArray(), - BinaryDictUtils.getDictionaryOptions(testName, version)); + BinaryDictUtils.makeDictionaryOptions(testName, version)); dict.add("abcd", 10, null, false); try { @@ -301,7 +301,7 @@ public class BinaryDictIOUtilsTests extends AndroidTestCase { // set an initial dictionary. final FusionDictionary dict = new FusionDictionary(new PtNodeArray(), - BinaryDictUtils.getDictionaryOptions(testName, version)); + BinaryDictUtils.makeDictionaryOptions(testName, version)); dict.add("abcd", 10, null, false); dict.add("efgh", 15, null, false); @@ -341,7 +341,7 @@ public class BinaryDictIOUtilsTests extends AndroidTestCase { // set an initial dictionary. final FusionDictionary dict = new FusionDictionary(new PtNodeArray(), - BinaryDictUtils.getDictionaryOptions(testName, version)); + BinaryDictUtils.makeDictionaryOptions(testName, version)); dict.add("initial", 10, null, false); try { diff --git a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictUtils.java b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictUtils.java index 5ec37255d..8b1521a6c 100644 --- a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictUtils.java +++ b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictUtils.java @@ -16,6 +16,7 @@ package com.android.inputmethod.latin.makedict; +import com.android.inputmethod.latin.makedict.FormatSpec.FileHeader; import com.android.inputmethod.latin.makedict.FormatSpec.FormatOptions; import com.android.inputmethod.latin.makedict.FusionDictionary.DictionaryOptions; @@ -41,11 +42,12 @@ public class BinaryDictUtils { new FormatSpec.FormatOptions(4, true /* supportsDynamicUpdate */, true /* hasTimestamp */); - public static DictionaryOptions getDictionaryOptions(final String id, final String version) { + public static DictionaryOptions makeDictionaryOptions(final String id, final String version) { final DictionaryOptions options = new DictionaryOptions(new HashMap(), false /* germanUmlautProcessing */, false /* frenchLigatureProcessing */); - options.mAttributes.put("dictionary", id); - options.mAttributes.put("version", version); + options.mAttributes.put(FileHeader.DICTIONARY_LOCALE_ATTRIBUTE, "en_US"); + options.mAttributes.put(FileHeader.DICTIONARY_ID_ATTRIBUTE, id); + options.mAttributes.put(FileHeader.DICTIONARY_VERSION_ATTRIBUTE, version); return options; }