From b986f78ba826fa360304a69565f1880bdd7ce0c5 Mon Sep 17 00:00:00 2001
From: Keisuke Kuroyanagi <ksk@google.com>
Date: Tue, 4 Feb 2014 21:36:04 +0900
Subject: [PATCH] Separate header class from FormatSpec.

Bug: 12810574
Change-Id: Iacf1cd05a268bf690ab864b5e32a18a4b0ccc693
---
 .../latin/BinaryDictionaryGetter.java         |  4 +-
 .../latin/ExpandableBinaryDictionary.java     |  7 +-
 .../ExternalDictionaryGetterForDebug.java     |  8 +-
 .../latin/makedict/AbstractDictDecoder.java   |  9 +--
 .../makedict/BinaryDictDecoderUtils.java      |  3 +-
 .../latin/makedict/BinaryDictIOUtils.java     | 11 ++-
 .../latin/makedict/DictDecoder.java           |  3 +-
 .../latin/makedict/DictionaryHeader.java      | 81 +++++++++++++++++++
 .../latin/makedict/FormatSpec.java            | 61 --------------
 .../latin/makedict/Ver2DictDecoder.java       |  5 +-
 .../latin/makedict/Ver4DictDecoder.java       |  5 +-
 .../latin/makedict/Ver4DictEncoder.java       |  2 +-
 ...ecayingExpandableBinaryDictionaryBase.java | 16 ++--
 .../latin/utils/DictionaryInfoUtils.java      |  6 +-
 .../latin/BinaryDictionaryDecayingTests.java  | 15 ++--
 .../BinaryDictDecoderEncoderTests.java        |  3 +-
 .../latin/makedict/BinaryDictUtils.java       | 15 ++--
 .../BinaryDictOffdeviceUtilsTests.java        | 13 +--
 18 files changed, 141 insertions(+), 126 deletions(-)
 create mode 100644 java/src/com/android/inputmethod/latin/makedict/DictionaryHeader.java

diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java
index 7e97802e1d..a7008379f2 100644
--- a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java
+++ b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java
@@ -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) {
diff --git a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java
index 226c3c8223..f0dc7720d7 100644
--- a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java
+++ b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java
@@ -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;
     }
diff --git a/java/src/com/android/inputmethod/latin/debug/ExternalDictionaryGetterForDebug.java b/java/src/com/android/inputmethod/latin/debug/ExternalDictionaryGetterForDebug.java
index 028f78a87b..800f565972 100644
--- a/java/src/com/android/inputmethod/latin/debug/ExternalDictionaryGetterForDebug.java
+++ b/java/src/com/android/inputmethod/latin/debug/ExternalDictionaryGetterForDebug.java
@@ -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 {
diff --git a/java/src/com/android/inputmethod/latin/makedict/AbstractDictDecoder.java b/java/src/com/android/inputmethod/latin/makedict/AbstractDictDecoder.java
index 1a9118147c..5c7c4b8e3f 100644
--- a/java/src/com/android/inputmethod/latin/makedict/AbstractDictDecoder.java
+++ b/java/src/com/android/inputmethod/latin/makedict/AbstractDictDecoder.java
@@ -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;
     }
 
diff --git a/java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderUtils.java b/java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderUtils.java
index 31747155ef..369184573a 100644
--- a/java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderUtils.java
+++ b/java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderUtils.java
@@ -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>();
diff --git a/java/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java b/java/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java
index 0dc50d14e0..dea9f2e28c 100644
--- a/java/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java
+++ b/java/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java
@@ -20,7 +20,6 @@ import com.android.inputmethod.annotations.UsedForTesting;
 import com.android.inputmethod.latin.Constants;
 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.PtNode;
 import com.android.inputmethod.latin.utils.ByteArrayDictBuffer;
@@ -151,7 +150,7 @@ public final class BinaryDictIOUtils {
             final Map<Integer, ArrayList<PendingAttribute>> bigrams) throws IOException,
             UnsupportedFormatException {
         // Read header
-        final FileHeader header = dictDecoder.readHeader();
+        final DictionaryHeader header = dictDecoder.readHeader();
         readUnigramsAndBigramsBinaryInner(dictDecoder, header.mBodyOffset, words,
                 frequencies, bigrams, header.mFormatOptions);
     }
@@ -172,7 +171,7 @@ public final class BinaryDictIOUtils {
         if (word == null) return FormatSpec.NOT_VALID_WORD;
         dictDecoder.setPosition(0);
 
-        final FileHeader header = dictDecoder.readHeader();
+        final DictionaryHeader header = dictDecoder.readHeader();
         int wordPos = 0;
         final int wordLen = word.codePointCount(0, word.length());
         for (int depth = 0; depth < Constants.DICTIONARY_MAX_WORD_LENGTH; ++depth) {
@@ -311,7 +310,7 @@ public final class BinaryDictIOUtils {
      * @param length The length of the data file.
      * @return the header of the specified dictionary file.
      */
-    private static FileHeader getDictionaryFileHeader(
+    private static DictionaryHeader getDictionaryFileHeader(
             final File file, final long offset, final long length)
             throws FileNotFoundException, IOException, UnsupportedFormatException {
         final byte[] buffer = new byte[HEADER_READING_BUFFER_SIZE];
@@ -337,10 +336,10 @@ public final class BinaryDictIOUtils {
         return dictDecoder.readHeader();
     }
 
-    public static FileHeader getDictionaryFileHeaderOrNull(final File file, final long offset,
+    public static DictionaryHeader getDictionaryFileHeaderOrNull(final File file, final long offset,
             final long length) {
         try {
-            final FileHeader header = getDictionaryFileHeader(file, offset, length);
+            final DictionaryHeader header = getDictionaryFileHeader(file, offset, length);
             return header;
         } catch (UnsupportedFormatException e) {
             return null;
diff --git a/java/src/com/android/inputmethod/latin/makedict/DictDecoder.java b/java/src/com/android/inputmethod/latin/makedict/DictDecoder.java
index b4838f00f4..bba1d434f9 100644
--- a/java/src/com/android/inputmethod/latin/makedict/DictDecoder.java
+++ b/java/src/com/android/inputmethod/latin/makedict/DictDecoder.java
@@ -18,7 +18,6 @@ package com.android.inputmethod.latin.makedict;
 
 import com.android.inputmethod.annotations.UsedForTesting;
 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.utils.ByteArrayDictBuffer;
 
@@ -41,7 +40,7 @@ public interface DictDecoder {
     /**
      * Reads and returns the file header.
      */
-    public FileHeader readHeader() throws IOException, UnsupportedFormatException;
+    public DictionaryHeader readHeader() throws IOException, UnsupportedFormatException;
 
     /**
      * Reads PtNode from ptNodePos.
diff --git a/java/src/com/android/inputmethod/latin/makedict/DictionaryHeader.java b/java/src/com/android/inputmethod/latin/makedict/DictionaryHeader.java
new file mode 100644
index 0000000000..b99e281dac
--- /dev/null
+++ b/java/src/com/android/inputmethod/latin/makedict/DictionaryHeader.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.inputmethod.latin.makedict;
+
+import com.android.inputmethod.latin.makedict.FormatSpec.FormatOptions;
+import com.android.inputmethod.latin.makedict.FusionDictionary.DictionaryOptions;
+
+/**
+ * Class representing dictionary header.
+ */
+public final class DictionaryHeader {
+    public final int mBodyOffset;
+    public final DictionaryOptions mDictionaryOptions;
+    public final FormatOptions mFormatOptions;
+
+    // Note that these are corresponding definitions in native code in latinime::HeaderPolicy
+    // and latinime::HeaderReadWriteUtils.
+    // TODO: Standardize the key names and bump up the format version, taking care not to
+    // break format version 2 dictionaries.
+    public static final String DICTIONARY_VERSION_KEY = "version";
+    public static final String DICTIONARY_LOCALE_KEY = "locale";
+    public static final String DICTIONARY_ID_KEY = "dictionary";
+    public static final String DICTIONARY_DESCRIPTION_KEY = "description";
+    public static final String DICTIONARY_DATE_KEY = "date";
+    public static final String HAS_HISTORICAL_INFO_KEY = "HAS_HISTORICAL_INFO";
+    public static final String USES_FORGETTING_CURVE_KEY = "USES_FORGETTING_CURVE";
+    public static final String ATTRIBUTE_VALUE_TRUE = "1";
+
+    public DictionaryHeader(final int headerSize, final DictionaryOptions dictionaryOptions,
+            final FormatOptions formatOptions) throws UnsupportedFormatException {
+        mDictionaryOptions = dictionaryOptions;
+        mFormatOptions = formatOptions;
+        mBodyOffset = formatOptions.mVersion < FormatSpec.VERSION4 ? headerSize : 0;
+        if (null == getLocaleString()) {
+            throw new UnsupportedFormatException("Cannot create a FileHeader without a locale");
+        }
+        if (null == getVersion()) {
+            throw new UnsupportedFormatException(
+                    "Cannot create a FileHeader without a version");
+        }
+        if (null == getId()) {
+            throw new UnsupportedFormatException("Cannot create a FileHeader without an ID");
+        }
+    }
+
+    // Helper method to get the locale as a String
+    public String getLocaleString() {
+        return mDictionaryOptions.mAttributes.get(DICTIONARY_LOCALE_KEY);
+    }
+
+    // Helper method to get the version String
+    public String getVersion() {
+        return mDictionaryOptions.mAttributes.get(DICTIONARY_VERSION_KEY);
+    }
+
+    // Helper method to get the dictionary ID as a String
+    public String getId() {
+        return mDictionaryOptions.mAttributes.get(DICTIONARY_ID_KEY);
+    }
+
+    // Helper method to get the description
+    public String getDescription() {
+        // TODO: Right now each dictionary file comes with a description in its own language.
+        // It will display as is no matter the device's locale. It should be internationalized.
+        return mDictionaryOptions.mAttributes.get(DICTIONARY_DESCRIPTION_KEY);
+    }
+}
\ No newline at end of file
diff --git a/java/src/com/android/inputmethod/latin/makedict/FormatSpec.java b/java/src/com/android/inputmethod/latin/makedict/FormatSpec.java
index 74e3059763..5a38073890 100644
--- a/java/src/com/android/inputmethod/latin/makedict/FormatSpec.java
+++ b/java/src/com/android/inputmethod/latin/makedict/FormatSpec.java
@@ -19,7 +19,6 @@ package com.android.inputmethod.latin.makedict;
 import com.android.inputmethod.annotations.UsedForTesting;
 import com.android.inputmethod.latin.Constants;
 import com.android.inputmethod.latin.makedict.DictDecoder.DictionaryBufferFactory;
-import com.android.inputmethod.latin.makedict.FusionDictionary.DictionaryOptions;
 
 import java.io.File;
 
@@ -329,66 +328,6 @@ public final class FormatSpec {
         }
     }
 
-    /**
-     * Class representing file header.
-     */
-    public static final class FileHeader {
-        public final int mBodyOffset;
-        public final DictionaryOptions mDictionaryOptions;
-        public final FormatOptions mFormatOptions;
-
-        // Note that these are corresponding definitions in native code in latinime::HeaderPolicy
-        // and latinime::HeaderReadWriteUtils.
-        // TODO: Standardize the key names and bump up the format version, taking care not to
-        // break format version 2 dictionaries.
-        public static final String DICTIONARY_VERSION_KEY = "version";
-        public static final String DICTIONARY_LOCALE_KEY = "locale";
-        public static final String DICTIONARY_ID_KEY = "dictionary";
-        public static final String DICTIONARY_DESCRIPTION_KEY = "description";
-        public static final String DICTIONARY_DATE_KEY = "date";
-        public static final String HAS_HISTORICAL_INFO_KEY = "HAS_HISTORICAL_INFO";
-        public static final String USES_FORGETTING_CURVE_KEY = "USES_FORGETTING_CURVE";
-        public static final String ATTRIBUTE_VALUE_TRUE = "1";
-        public FileHeader(final int headerSize, final DictionaryOptions dictionaryOptions,
-                final FormatOptions formatOptions) throws UnsupportedFormatException {
-            mDictionaryOptions = dictionaryOptions;
-            mFormatOptions = formatOptions;
-            mBodyOffset = formatOptions.mVersion < VERSION4 ? headerSize : 0;
-            if (null == getLocaleString()) {
-                throw new UnsupportedFormatException("Cannot create a FileHeader without a locale");
-            }
-            if (null == getVersion()) {
-                throw new UnsupportedFormatException(
-                        "Cannot create a FileHeader without a version");
-            }
-            if (null == getId()) {
-                throw new UnsupportedFormatException("Cannot create a FileHeader without an ID");
-            }
-        }
-
-        // Helper method to get the locale as a String
-        public String getLocaleString() {
-            return mDictionaryOptions.mAttributes.get(FileHeader.DICTIONARY_LOCALE_KEY);
-        }
-
-        // Helper method to get the version String
-        public String getVersion() {
-            return mDictionaryOptions.mAttributes.get(FileHeader.DICTIONARY_VERSION_KEY);
-        }
-
-        // Helper method to get the dictionary ID as a String
-        public String getId() {
-            return mDictionaryOptions.mAttributes.get(FileHeader.DICTIONARY_ID_KEY);
-        }
-
-        // Helper method to get the description
-        public String getDescription() {
-            // TODO: Right now each dictionary file comes with a description in its own language.
-            // It will display as is no matter the device's locale. It should be internationalized.
-            return mDictionaryOptions.mAttributes.get(FileHeader.DICTIONARY_DESCRIPTION_KEY);
-        }
-    }
-
     /**
      * Returns new dictionary decoder.
      *
diff --git a/java/src/com/android/inputmethod/latin/makedict/Ver2DictDecoder.java b/java/src/com/android/inputmethod/latin/makedict/Ver2DictDecoder.java
index ea0a2c6c2d..d35f780cff 100644
--- a/java/src/com/android/inputmethod/latin/makedict/Ver2DictDecoder.java
+++ b/java/src/com/android/inputmethod/latin/makedict/Ver2DictDecoder.java
@@ -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.PtNode;
 import com.android.inputmethod.latin.makedict.FusionDictionary.WeightedString;
@@ -90,11 +89,11 @@ public class Ver2DictDecoder extends AbstractDictDecoder {
     }
 
     @Override
-    public FileHeader readHeader() throws IOException, UnsupportedFormatException {
+    public DictionaryHeader readHeader() throws IOException, UnsupportedFormatException {
         if (mDictBuffer == null) {
             openDictBuffer();
         }
-        final FileHeader header = super.readHeader(mDictBuffer);
+        final DictionaryHeader header = super.readHeader(mDictBuffer);
         final int version = header.mFormatOptions.mVersion;
         if (!(version >= 2 && version <= 3)) {
           throw new UnsupportedFormatException("File header has a wrong version : " + version);
diff --git a/java/src/com/android/inputmethod/latin/makedict/Ver4DictDecoder.java b/java/src/com/android/inputmethod/latin/makedict/Ver4DictDecoder.java
index e459e48615..9ddaaf7343 100644
--- a/java/src/com/android/inputmethod/latin/makedict/Ver4DictDecoder.java
+++ b/java/src/com/android/inputmethod/latin/makedict/Ver4DictDecoder.java
@@ -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.PtNode;
 import com.android.inputmethod.latin.makedict.FusionDictionary.WeightedString;
@@ -166,12 +165,12 @@ public class Ver4DictDecoder extends AbstractDictDecoder {
     }
 
     @Override
-    public FileHeader readHeader() throws IOException, UnsupportedFormatException {
+    public DictionaryHeader readHeader() throws IOException, UnsupportedFormatException {
         if (mHeaderBuffer == null) {
             openDictBuffer();
         }
         mHeaderBuffer.position(0);
-        final FileHeader header = super.readHeader(mHeaderBuffer);
+        final DictionaryHeader header = super.readHeader(mHeaderBuffer);
         final int version = header.mFormatOptions.mVersion;
         if (version != FormatSpec.VERSION4) {
             throw new UnsupportedFormatException("File header has a wrong version : " + version);
diff --git a/java/src/com/android/inputmethod/latin/makedict/Ver4DictEncoder.java b/java/src/com/android/inputmethod/latin/makedict/Ver4DictEncoder.java
index b12f79b078..160775d63e 100644
--- a/java/src/com/android/inputmethod/latin/makedict/Ver4DictEncoder.java
+++ b/java/src/com/android/inputmethod/latin/makedict/Ver4DictEncoder.java
@@ -62,7 +62,7 @@ public class Ver4DictEncoder implements DictEncoder {
         final BinaryDictionary binaryDict = new BinaryDictionary(mDictPlacedDir.getAbsolutePath(),
                 0l, mDictPlacedDir.length(), true /* useFullEditDistance */,
                 LocaleUtils.constructLocaleFromString(dict.mOptions.mAttributes.get(
-                        FormatSpec.FileHeader.DICTIONARY_LOCALE_KEY)),
+                        DictionaryHeader.DICTIONARY_LOCALE_KEY)),
                 Dictionary.TYPE_USER /* Dictionary type. Does not matter for us */,
                 true /* isUpdatable */);
         if (!binaryDict.isValidDictionary()) {
diff --git a/java/src/com/android/inputmethod/latin/personalization/DecayingExpandableBinaryDictionaryBase.java b/java/src/com/android/inputmethod/latin/personalization/DecayingExpandableBinaryDictionaryBase.java
index cd6a3aa92f..6a7a3368e4 100644
--- a/java/src/com/android/inputmethod/latin/personalization/DecayingExpandableBinaryDictionaryBase.java
+++ b/java/src/com/android/inputmethod/latin/personalization/DecayingExpandableBinaryDictionaryBase.java
@@ -22,7 +22,7 @@ import com.android.inputmethod.annotations.UsedForTesting;
 import com.android.inputmethod.latin.Constants;
 import com.android.inputmethod.latin.Dictionary;
 import com.android.inputmethod.latin.ExpandableBinaryDictionary;
-import com.android.inputmethod.latin.makedict.FormatSpec;
+import com.android.inputmethod.latin.makedict.DictionaryHeader;
 import com.android.inputmethod.latin.utils.LanguageModelParam;
 
 import java.io.File;
@@ -86,13 +86,13 @@ public abstract class DecayingExpandableBinaryDictionaryBase extends ExpandableB
     @Override
     protected Map<String, String> getHeaderAttributeMap() {
         HashMap<String, String> attributeMap = new HashMap<String, String>();
-        attributeMap.put(FormatSpec.FileHeader.USES_FORGETTING_CURVE_KEY,
-                FormatSpec.FileHeader.ATTRIBUTE_VALUE_TRUE);
-        attributeMap.put(FormatSpec.FileHeader.HAS_HISTORICAL_INFO_KEY,
-                FormatSpec.FileHeader.ATTRIBUTE_VALUE_TRUE);
-        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.USES_FORGETTING_CURVE_KEY,
+                DictionaryHeader.ATTRIBUTE_VALUE_TRUE);
+        attributeMap.put(DictionaryHeader.HAS_HISTORICAL_INFO_KEY,
+                DictionaryHeader.ATTRIBUTE_VALUE_TRUE);
+        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;
     }
diff --git a/java/src/com/android/inputmethod/latin/utils/DictionaryInfoUtils.java b/java/src/com/android/inputmethod/latin/utils/DictionaryInfoUtils.java
index 306735779c..a155565111 100644
--- a/java/src/com/android/inputmethod/latin/utils/DictionaryInfoUtils.java
+++ b/java/src/com/android/inputmethod/latin/utils/DictionaryInfoUtils.java
@@ -29,7 +29,7 @@ import com.android.inputmethod.latin.BinaryDictionaryGetter;
 import com.android.inputmethod.latin.Constants;
 import com.android.inputmethod.latin.R;
 import com.android.inputmethod.latin.makedict.BinaryDictIOUtils;
-import com.android.inputmethod.latin.makedict.FormatSpec.FileHeader;
+import com.android.inputmethod.latin.makedict.DictionaryHeader;
 import com.android.inputmethod.latin.settings.SpacingAndPunctuations;
 
 import java.io.File;
@@ -282,7 +282,7 @@ public class DictionaryInfoUtils {
                 BinaryDictionaryGetter.ID_CATEGORY_SEPARATOR + locale.getLanguage().toString();
     }
 
-    public static FileHeader getDictionaryFileHeaderOrNull(final File file) {
+    public static DictionaryHeader getDictionaryFileHeaderOrNull(final File file) {
         return BinaryDictIOUtils.getDictionaryFileHeaderOrNull(file, 0, file.length());
     }
 
@@ -294,7 +294,7 @@ public class DictionaryInfoUtils {
      */
     private static DictionaryInfo createDictionaryInfoFromFileAddress(
             final AssetFileAddress fileAddress) {
-        final FileHeader header = BinaryDictIOUtils.getDictionaryFileHeaderOrNull(
+        final DictionaryHeader header = BinaryDictIOUtils.getDictionaryFileHeaderOrNull(
                 new File(fileAddress.mFilename), fileAddress.mOffset, fileAddress.mLength);
         if (header == null) {
             return null;
diff --git a/tests/src/com/android/inputmethod/latin/BinaryDictionaryDecayingTests.java b/tests/src/com/android/inputmethod/latin/BinaryDictionaryDecayingTests.java
index 343ab420c9..c41bbd7687 100644
--- a/tests/src/com/android/inputmethod/latin/BinaryDictionaryDecayingTests.java
+++ b/tests/src/com/android/inputmethod/latin/BinaryDictionaryDecayingTests.java
@@ -22,6 +22,7 @@ import android.util.Pair;
 
 import com.android.inputmethod.latin.makedict.CodePointUtils;
 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.FusionDictionary;
 import com.android.inputmethod.latin.makedict.FusionDictionary.PtNode;
@@ -102,14 +103,14 @@ public class BinaryDictionaryDecayingTests extends AndroidTestCase {
                 getContext().getCacheDir());
         FileUtils.deleteRecursively(file);
         Map<String, String> attributeMap = new HashMap<String, String>();
-        attributeMap.put(FormatSpec.FileHeader.DICTIONARY_ID_KEY, dictId);
-        attributeMap.put(FormatSpec.FileHeader.DICTIONARY_LOCALE_KEY, dictId);
-        attributeMap.put(FormatSpec.FileHeader.DICTIONARY_VERSION_KEY,
+        attributeMap.put(DictionaryHeader.DICTIONARY_ID_KEY, dictId);
+        attributeMap.put(DictionaryHeader.DICTIONARY_LOCALE_KEY, dictId);
+        attributeMap.put(DictionaryHeader.DICTIONARY_VERSION_KEY,
                 String.valueOf(TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis())));
-        attributeMap.put(FormatSpec.FileHeader.USES_FORGETTING_CURVE_KEY,
-                FormatSpec.FileHeader.ATTRIBUTE_VALUE_TRUE);
-        attributeMap.put(FormatSpec.FileHeader.HAS_HISTORICAL_INFO_KEY,
-                FormatSpec.FileHeader.ATTRIBUTE_VALUE_TRUE);
+        attributeMap.put(DictionaryHeader.USES_FORGETTING_CURVE_KEY,
+                DictionaryHeader.ATTRIBUTE_VALUE_TRUE);
+        attributeMap.put(DictionaryHeader.HAS_HISTORICAL_INFO_KEY,
+                DictionaryHeader.ATTRIBUTE_VALUE_TRUE);
         if (BinaryDictionary.createEmptyDictFile(file.getAbsolutePath(),
                 FormatSpec.VERSION4, attributeMap)) {
             return file;
diff --git a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java
index 715db2f9bc..0815819d6b 100644
--- a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java
+++ b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java
@@ -24,7 +24,6 @@ import android.util.SparseArray;
 import com.android.inputmethod.latin.BinaryDictionary;
 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.PtNode;
 import com.android.inputmethod.latin.makedict.FusionDictionary.PtNodeArray;
@@ -498,7 +497,7 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase {
     private String getWordFromBinary(final DictDecoder dictDecoder, final int address) {
         if (dictDecoder.getPosition() != 0) dictDecoder.setPosition(0);
 
-        FileHeader fileHeader = null;
+        DictionaryHeader fileHeader = null;
         try {
             fileHeader = dictDecoder.readHeader();
         } catch (IOException e) {
diff --git a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictUtils.java b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictUtils.java
index 20cf9a5629..79f3e0dc9b 100644
--- a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictUtils.java
+++ b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictUtils.java
@@ -16,7 +16,6 @@
 
 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;
 
@@ -39,14 +38,14 @@ public class BinaryDictUtils {
     public static DictionaryOptions makeDictionaryOptions(final String id, final String version,
             final FormatSpec.FormatOptions formatOptions) {
         final DictionaryOptions options = new DictionaryOptions(new HashMap<String, String>());
-        options.mAttributes.put(FileHeader.DICTIONARY_LOCALE_KEY, "en_US");
-        options.mAttributes.put(FileHeader.DICTIONARY_ID_KEY, id);
-        options.mAttributes.put(FileHeader.DICTIONARY_VERSION_KEY, version);
+        options.mAttributes.put(DictionaryHeader.DICTIONARY_LOCALE_KEY, "en_US");
+        options.mAttributes.put(DictionaryHeader.DICTIONARY_ID_KEY, id);
+        options.mAttributes.put(DictionaryHeader.DICTIONARY_VERSION_KEY, version);
         if (formatOptions.mHasTimestamp) {
-            options.mAttributes.put(FileHeader.HAS_HISTORICAL_INFO_KEY,
-                    FileHeader.ATTRIBUTE_VALUE_TRUE);
-            options.mAttributes.put(FileHeader.USES_FORGETTING_CURVE_KEY,
-                    FileHeader.ATTRIBUTE_VALUE_TRUE);
+            options.mAttributes.put(DictionaryHeader.HAS_HISTORICAL_INFO_KEY,
+                    DictionaryHeader.ATTRIBUTE_VALUE_TRUE);
+            options.mAttributes.put(DictionaryHeader.USES_FORGETTING_CURVE_KEY,
+                    DictionaryHeader.ATTRIBUTE_VALUE_TRUE);
         }
         return options;
     }
diff --git a/tools/dicttool/tests/com/android/inputmethod/latin/dicttool/BinaryDictOffdeviceUtilsTests.java b/tools/dicttool/tests/com/android/inputmethod/latin/dicttool/BinaryDictOffdeviceUtilsTests.java
index d8059e428e..9ed4dd5a2f 100644
--- a/tools/dicttool/tests/com/android/inputmethod/latin/dicttool/BinaryDictOffdeviceUtilsTests.java
+++ b/tools/dicttool/tests/com/android/inputmethod/latin/dicttool/BinaryDictOffdeviceUtilsTests.java
@@ -18,6 +18,7 @@ package com.android.inputmethod.latin.dicttool;
 
 import com.android.inputmethod.latin.makedict.DictDecoder;
 import com.android.inputmethod.latin.makedict.DictEncoder;
+import com.android.inputmethod.latin.makedict.DictionaryHeader;
 import com.android.inputmethod.latin.makedict.FormatSpec;
 import com.android.inputmethod.latin.makedict.FormatSpec.FormatOptions;
 import com.android.inputmethod.latin.makedict.FusionDictionary;
@@ -48,9 +49,9 @@ public class BinaryDictOffdeviceUtilsTests extends TestCase {
 
         // Create a thrice-compressed dictionary file.
         final DictionaryOptions testOptions = new DictionaryOptions(new HashMap<String, String>());
-        testOptions.mAttributes.put(FormatSpec.FileHeader.DICTIONARY_VERSION_KEY, VERSION);
-        testOptions.mAttributes.put(FormatSpec.FileHeader.DICTIONARY_LOCALE_KEY, LOCALE);
-        testOptions.mAttributes.put(FormatSpec.FileHeader.DICTIONARY_ID_KEY, ID);
+        testOptions.mAttributes.put(DictionaryHeader.DICTIONARY_VERSION_KEY, VERSION);
+        testOptions.mAttributes.put(DictionaryHeader.DICTIONARY_LOCALE_KEY, LOCALE);
+        testOptions.mAttributes.put(DictionaryHeader.DICTIONARY_ID_KEY, ID);
         final FusionDictionary dict = new FusionDictionary(new PtNodeArray(), testOptions);
         dict.add("foo", TEST_FREQ, null, false /* isNotAWord */);
         dict.add("fta", 1, null, false /* isNotAWord */);
@@ -80,11 +81,11 @@ public class BinaryDictOffdeviceUtilsTests extends TestCase {
                 null /* dict : an optional dictionary to add words to, or null */,
                 false /* deleteDictIfBroken */);
         assertEquals("Wrong version attribute", VERSION, resultDict.mOptions.mAttributes.get(
-                FormatSpec.FileHeader.DICTIONARY_VERSION_KEY));
+                DictionaryHeader.DICTIONARY_VERSION_KEY));
         assertEquals("Wrong locale attribute", LOCALE, resultDict.mOptions.mAttributes.get(
-                FormatSpec.FileHeader.DICTIONARY_LOCALE_KEY));
+                DictionaryHeader.DICTIONARY_LOCALE_KEY));
         assertEquals("Wrong id attribute", ID, resultDict.mOptions.mAttributes.get(
-                FormatSpec.FileHeader.DICTIONARY_ID_KEY));
+                DictionaryHeader.DICTIONARY_ID_KEY));
         assertEquals("Dictionary can't be read back correctly",
                 FusionDictionary.findWordInTree(resultDict.mRootNodeArray, "foo").getFrequency(),
                 TEST_FREQ);
-- 
GitLab