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

Commit b986f78b authored by Keisuke Kuroyanagi's avatar Keisuke Kuroyanagi
Browse files

Separate header class from FormatSpec.

Bug: 12810574
Change-Id: Iacf1cd05a268bf690ab864b5e32a18a4b0ccc693
parent 36c7a62d
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -22,8 +22,8 @@ import android.content.res.AssetFileDescriptor;
import android.util.Log;

import com.android.inputmethod.latin.makedict.DictDecoder;
import com.android.inputmethod.latin.makedict.DictionaryHeader;
import com.android.inputmethod.latin.makedict.FormatSpec;
import com.android.inputmethod.latin.makedict.FormatSpec.FileHeader;
import com.android.inputmethod.latin.makedict.UnsupportedFormatException;
import com.android.inputmethod.latin.utils.CollectionUtils;
import com.android.inputmethod.latin.utils.DictionaryInfoUtils;
@@ -230,7 +230,7 @@ final public class BinaryDictionaryGetter {
        try {
            // Read the version of the file
            final DictDecoder dictDecoder = FormatSpec.getDictDecoder(f);
            final FileHeader header = dictDecoder.readHeader();
            final DictionaryHeader header = dictDecoder.readHeader();

            final String version = header.mDictionaryOptions.mAttributes.get(VERSION_KEY);
            if (null == version) {
+4 −3
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.util.Log;

import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.keyboard.ProximityInfo;
import com.android.inputmethod.latin.makedict.DictionaryHeader;
import com.android.inputmethod.latin.makedict.FormatSpec;
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import com.android.inputmethod.latin.utils.AsyncResultHolder;
@@ -268,9 +269,9 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {

    protected Map<String, String> getHeaderAttributeMap() {
        HashMap<String, String> attributeMap = new HashMap<String, String>();
        attributeMap.put(FormatSpec.FileHeader.DICTIONARY_ID_KEY, mDictName);
        attributeMap.put(FormatSpec.FileHeader.DICTIONARY_LOCALE_KEY, mLocale.toString());
        attributeMap.put(FormatSpec.FileHeader.DICTIONARY_VERSION_KEY,
        attributeMap.put(DictionaryHeader.DICTIONARY_ID_KEY, mDictName);
        attributeMap.put(DictionaryHeader.DICTIONARY_LOCALE_KEY, mLocale.toString());
        attributeMap.put(DictionaryHeader.DICTIONARY_VERSION_KEY,
                String.valueOf(TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis())));
        return attributeMap;
    }
+4 −4
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@ import android.os.Environment;
import com.android.inputmethod.latin.BinaryDictionaryFileDumper;
import com.android.inputmethod.latin.BinaryDictionaryGetter;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.makedict.FormatSpec.FileHeader;
import com.android.inputmethod.latin.makedict.DictionaryHeader;
import com.android.inputmethod.latin.utils.CollectionUtils;
import com.android.inputmethod.latin.utils.DictionaryInfoUtils;
import com.android.inputmethod.latin.utils.LocaleUtils;
@@ -51,7 +51,7 @@ public class ExternalDictionaryGetterForDebug {
        final File[] files = new File(SOURCE_FOLDER).listFiles();
        final ArrayList<String> eligibleList = CollectionUtils.newArrayList();
        for (File f : files) {
            final FileHeader header = DictionaryInfoUtils.getDictionaryFileHeaderOrNull(f);
            final DictionaryHeader header = DictionaryInfoUtils.getDictionaryFileHeaderOrNull(f);
            if (null == header) continue;
            eligibleList.add(f.getName());
        }
@@ -99,7 +99,7 @@ public class ExternalDictionaryGetterForDebug {
    public static void askInstallFile(final Context context, final String dirPath,
            final String fileName, final Runnable completeRunnable) {
        final File file = new File(dirPath, fileName.toString());
        final FileHeader header = DictionaryInfoUtils.getDictionaryFileHeaderOrNull(file);
        final DictionaryHeader header = DictionaryInfoUtils.getDictionaryFileHeaderOrNull(file);
        final StringBuilder message = new StringBuilder();
        final String locale = header.getLocaleString();
        for (String key : header.mDictionaryOptions.mAttributes.keySet()) {
@@ -143,7 +143,7 @@ public class ExternalDictionaryGetterForDebug {
    }

    private static void installFile(final Context context, final File file,
            final FileHeader header) {
            final DictionaryHeader header) {
        BufferedOutputStream outputStream = null;
        File tempFile = null;
        try {
+4 −5
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ package com.android.inputmethod.latin.makedict;
import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.latin.makedict.BinaryDictDecoderUtils.CharEncoding;
import com.android.inputmethod.latin.makedict.BinaryDictDecoderUtils.DictBuffer;
import com.android.inputmethod.latin.makedict.FormatSpec.FileHeader;
import com.android.inputmethod.latin.makedict.FormatSpec.FormatOptions;
import com.android.inputmethod.latin.makedict.FusionDictionary.WeightedString;

@@ -36,7 +35,7 @@ public abstract class AbstractDictDecoder implements DictDecoder {
    private static final int ERROR_CANNOT_READ = 1;
    private static final int ERROR_WRONG_FORMAT = 2;

    protected FileHeader readHeader(final DictBuffer headerBuffer)
    protected DictionaryHeader readHeader(final DictBuffer headerBuffer)
            throws IOException, UnsupportedFormatException {
        if (headerBuffer == null) {
            openDictBuffer();
@@ -57,10 +56,10 @@ public abstract class AbstractDictDecoder implements DictDecoder {
        final HashMap<String, String> attributes = HeaderReader.readAttributes(headerBuffer,
                headerSize);

        final FileHeader header = new FileHeader(headerSize,
        final DictionaryHeader header = new DictionaryHeader(headerSize,
                new FusionDictionary.DictionaryOptions(attributes),
                new FormatOptions(version, FileHeader.ATTRIBUTE_VALUE_TRUE.equals(
                        attributes.get(FileHeader.HAS_HISTORICAL_INFO_KEY))));
                new FormatOptions(version, DictionaryHeader.ATTRIBUTE_VALUE_TRUE.equals(
                        attributes.get(DictionaryHeader.HAS_HISTORICAL_INFO_KEY))));
        return header;
    }

+1 −2
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@
package com.android.inputmethod.latin.makedict;

import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.latin.makedict.FormatSpec.FileHeader;
import com.android.inputmethod.latin.makedict.FormatSpec.FormatOptions;
import com.android.inputmethod.latin.makedict.FusionDictionary.PtNode;
import com.android.inputmethod.latin.makedict.FusionDictionary.PtNodeArray;
@@ -598,7 +597,7 @@ public final class BinaryDictDecoderUtils {
    /* package */ static FusionDictionary readDictionaryBinary(final DictDecoder dictDecoder,
            final FusionDictionary dict) throws IOException, UnsupportedFormatException {
        // Read header
        final FileHeader fileHeader = dictDecoder.readHeader();
        final DictionaryHeader fileHeader = dictDecoder.readHeader();

        Map<Integer, PtNodeArray> reverseNodeArrayMapping = new TreeMap<Integer, PtNodeArray>();
        Map<Integer, PtNode> reversePtNodeMapping = new TreeMap<Integer, PtNode>();
Loading