am 95bc256f: Add a flag to readDictioanryBinary in DictDecoder.
* commit '95bc256f419e9e47c26dfefd1ac31266dac2f344': Add a flag to readDictioanryBinary in DictDecoder.main
commit
811e37b37b
|
@ -54,10 +54,13 @@ public interface DictDecoder {
|
|||
* which words from the buffer should be added. If it is null, a new dictionary is created.
|
||||
*
|
||||
* @param dict an optional dictionary to add words to, or null.
|
||||
* @param deleteDictIfBroken a flag indicating whether this method should remove the broken
|
||||
* dictionary or not.
|
||||
* @return the created (or merged) dictionary.
|
||||
*/
|
||||
@UsedForTesting
|
||||
public FusionDictionary readDictionaryBinary(final FusionDictionary dict)
|
||||
public FusionDictionary readDictionaryBinary(final FusionDictionary dict,
|
||||
final boolean deleteDictIfBroken)
|
||||
throws FileNotFoundException, IOException, UnsupportedFormatException;
|
||||
|
||||
/**
|
||||
|
|
|
@ -306,7 +306,8 @@ public class Ver3DictDecoder implements DictDecoder {
|
|||
}
|
||||
|
||||
@Override
|
||||
public FusionDictionary readDictionaryBinary(final FusionDictionary dict)
|
||||
public FusionDictionary readDictionaryBinary(final FusionDictionary dict,
|
||||
final boolean deleteDictIfBroken)
|
||||
throws FileNotFoundException, IOException, UnsupportedFormatException {
|
||||
if (mDictBuffer == null) {
|
||||
openDictBuffer();
|
||||
|
@ -315,13 +316,13 @@ public class Ver3DictDecoder implements DictDecoder {
|
|||
return BinaryDictDecoderUtils.readDictionaryBinary(this, dict);
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "The dictionary " + mDictionaryBinaryFile.getName() + " is broken.", e);
|
||||
if (!mDictionaryBinaryFile.delete()) {
|
||||
if (deleteDictIfBroken && !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()) {
|
||||
if (deleteDictIfBroken && !mDictionaryBinaryFile.delete()) {
|
||||
Log.e(TAG, "Failed to delete the broken dictionary.");
|
||||
}
|
||||
throw e;
|
||||
|
|
|
@ -289,7 +289,7 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase {
|
|||
dictDecoder.openDictBuffer();
|
||||
assertNotNull(dictDecoder.getDictBuffer());
|
||||
now = System.currentTimeMillis();
|
||||
dict = dictDecoder.readDictionaryBinary(null);
|
||||
dict = dictDecoder.readDictionaryBinary(null, false /* deleteDictIfBroken */);
|
||||
diff = System.currentTimeMillis() - now;
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "IOException while reading dictionary", e);
|
||||
|
|
|
@ -192,7 +192,7 @@ public final class BinaryDictOffdeviceUtils {
|
|||
System.out.println("Packaging : " + decodedSpec.describeChain());
|
||||
System.out.println("Uncompressed size : " + decodedSpec.mFile.length());
|
||||
}
|
||||
return dictDecoder.readDictionaryBinary(null);
|
||||
return dictDecoder.readDictionaryBinary(null, false /* deleteDictIfBroken */);
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
|
|
@ -268,7 +268,7 @@ public class DictionaryMaker {
|
|||
throws FileNotFoundException, IOException, UnsupportedFormatException {
|
||||
final File file = new File(binaryFilename);
|
||||
final DictDecoder dictDecoder = new Ver3DictDecoder(file);
|
||||
return dictDecoder.readDictionaryBinary(null);
|
||||
return dictDecoder.readDictionaryBinary(null, false /* deleteDictIfBroken */);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -71,7 +71,8 @@ public class BinaryDictOffdeviceUtilsTests extends TestCase {
|
|||
assertEquals("Wrong decode spec", 3, decodeSpec.mDecoderSpec.size());
|
||||
final DictDecoder dictDecoder = new Ver3DictDecoder(decodeSpec.mFile);
|
||||
final FusionDictionary resultDict = dictDecoder.readDictionaryBinary(
|
||||
null /* dict : an optional dictionary to add words to, or null */);
|
||||
null /* dict : an optional dictionary to add words to, or null */,
|
||||
false /* deleteDictIfBroken */);
|
||||
assertEquals("Dictionary can't be read back correctly",
|
||||
FusionDictionary.findWordInTree(resultDict.mRootNodeArray, "foo").getFrequency(),
|
||||
TEST_FREQ);
|
||||
|
|
Loading…
Reference in New Issue