Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 95bc256f authored by Yuichiro Hanada's avatar Yuichiro Hanada
Browse files

Add a flag to readDictioanryBinary in DictDecoder.

Change-Id: I356adb72047ebc43c924fbff1ff45e7460508a31
parent f7ec77fe
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -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;

    /**
+4 −3
Original line number Diff line number Diff line
@@ -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;
+1 −1
Original line number Diff line number Diff line
@@ -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);
+1 −1
Original line number Diff line number Diff line
@@ -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) {
+1 −1
Original line number Diff line number Diff line
@@ -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 */);
    }

    /**
Loading