diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionary.java b/java/src/com/android/inputmethod/latin/BinaryDictionary.java
index 05e6ef0d26cbf37243f5779c47622d4e38342f6d..a3a329a7128624efe2379f91812a6775c9de3324 100644
--- a/java/src/com/android/inputmethod/latin/BinaryDictionary.java
+++ b/java/src/com/android/inputmethod/latin/BinaryDictionary.java
@@ -199,7 +199,6 @@ public final class BinaryDictionary extends Dictionary {
         return true;
     }
 
-    @UsedForTesting
     public DictionaryHeader getHeader() throws UnsupportedFormatException {
         if (mNativeDict == 0) {
             return null;
diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java
index acbd919cd7e362b480d1a6830f082d4530649014..4c49cb31ccc087d965d29c49096f5100d7023c85 100644
--- a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java
+++ b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java
@@ -21,10 +21,9 @@ import android.content.SharedPreferences;
 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.UnsupportedFormatException;
+import com.android.inputmethod.latin.utils.BinaryDictionaryUtils;
 import com.android.inputmethod.latin.utils.CollectionUtils;
 import com.android.inputmethod.latin.utils.DictionaryInfoUtils;
 import com.android.inputmethod.latin.utils.LocaleUtils;
@@ -226,12 +225,10 @@ final public class BinaryDictionaryGetter {
     // ## HACK ## we prevent usage of a dictionary before version 18. The reason for this is, since
     // those do not include whitelist entries, the new code with an old version of the dictionary
     // would lose whitelist functionality.
-    private static boolean hackCanUseDictionaryFile(final Locale locale, final File f) {
+    private static boolean hackCanUseDictionaryFile(final Locale locale, final File file) {
         try {
             // Read the version of the file
-            final DictDecoder dictDecoder = FormatSpec.getDictDecoder(f, 0, f.length());
-            final DictionaryHeader header = dictDecoder.readHeader();
-
+            final DictionaryHeader header = BinaryDictionaryUtils.getHeader(file);
             final String version = header.mDictionaryOptions.mAttributes.get(VERSION_KEY);
             if (null == version) {
                 // No version in the options : the format is unexpected
diff --git a/java/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java b/java/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java
index 90e7400fbea164e4da078797a29489da7430e9d0..caf3cf3545d364b1ec79fb61d4d2f2a206537d88 100644
--- a/java/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java
+++ b/java/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java
@@ -222,54 +222,6 @@ public final class BinaryDictIOUtils {
         return countSize;
     }
 
-    private static final int HEADER_READING_BUFFER_SIZE = 16384;
-    /**
-     * Convenience method to read the header of a binary file.
-     *
-     * This is quite resource intensive - don't call when performance is critical.
-     *
-     * @param file The file to read.
-     * @param offset The offset in the file where to start reading the data.
-     * @param length The length of the data file.
-     * @return the header of the specified dictionary file.
-     */
-    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];
-        final DictDecoder dictDecoder = FormatSpec.getDictDecoder(file, offset, length,
-                new DictDecoder.DictionaryBufferFactory() {
-                    @Override
-                    public DictBuffer getDictionaryBuffer(File file)
-                            throws FileNotFoundException, IOException {
-                        final FileInputStream inStream = new FileInputStream(file);
-                        try {
-                            inStream.skip(offset);
-                            inStream.read(buffer);
-                            return new ByteArrayDictBuffer(buffer);
-                        } finally {
-                            inStream.close();
-                        }
-                    }
-                });
-        if (dictDecoder == null) {
-            return null;
-        }
-        return dictDecoder.readHeader();
-    }
-
-    public static DictionaryHeader getDictionaryFileHeaderOrNull(final File file, final long offset,
-            final long length) {
-        try {
-            final DictionaryHeader header = getDictionaryFileHeader(file, offset, length);
-            return header;
-        } catch (UnsupportedFormatException e) {
-            return null;
-        } catch (IOException e) {
-            return null;
-        }
-    }
-
     /**
      * Helper method to hide the actual value of the no children address.
      */
diff --git a/java/src/com/android/inputmethod/latin/makedict/FormatSpec.java b/java/src/com/android/inputmethod/latin/makedict/FormatSpec.java
index 9abecbfec9db040adb6f5c76e430bd0fe046d863..484bb4b23dfdfe2aad45620a21b7e068326aacf7 100644
--- a/java/src/com/android/inputmethod/latin/makedict/FormatSpec.java
+++ b/java/src/com/android/inputmethod/latin/makedict/FormatSpec.java
@@ -341,6 +341,7 @@ public final class FormatSpec {
         return null;
     }
 
+    @UsedForTesting
     public static DictDecoder getDictDecoder(final File dictFile, final long offset,
             final long length, final DictionaryBufferFactory factory) {
         if (dictFile.isDirectory()) {
@@ -351,6 +352,7 @@ public final class FormatSpec {
         return null;
     }
 
+    @UsedForTesting
     public static DictDecoder getDictDecoder(final File dictFile, final long offset,
             final long length) {
         return getDictDecoder(dictFile, offset, length, DictDecoder.USE_READONLY_BYTEBUFFER);
diff --git a/java/src/com/android/inputmethod/latin/makedict/Ver2DictDecoder.java b/java/src/com/android/inputmethod/latin/makedict/Ver2DictDecoder.java
index ae1e443c5fd96c3cf231f4c41caf68593c8bfae1..ab24fbc8472b94bde5e6da2c6b1bdab881cdc766 100644
--- a/java/src/com/android/inputmethod/latin/makedict/Ver2DictDecoder.java
+++ b/java/src/com/android/inputmethod/latin/makedict/Ver2DictDecoder.java
@@ -123,6 +123,7 @@ public class Ver2DictDecoder extends AbstractDictDecoder {
     private final DictionaryBufferFactory mBufferFactory;
     protected DictBuffer mDictBuffer;
 
+    @UsedForTesting
     /* package */ Ver2DictDecoder(final File file, final long offset, final long length,
             final int factoryFlag) {
         mDictionaryBinaryFile = file;
diff --git a/java/src/com/android/inputmethod/latin/utils/BinaryDictionaryUtils.java b/java/src/com/android/inputmethod/latin/utils/BinaryDictionaryUtils.java
index 6872285adee338d365d1b64d5e27af568b196acf..638830046cced8ee892904d05b0fe32af50788c0 100644
--- a/java/src/com/android/inputmethod/latin/utils/BinaryDictionaryUtils.java
+++ b/java/src/com/android/inputmethod/latin/utils/BinaryDictionaryUtils.java
@@ -17,8 +17,13 @@
 package com.android.inputmethod.latin.utils;
 
 import com.android.inputmethod.annotations.UsedForTesting;
+import com.android.inputmethod.latin.BinaryDictionary;
+import com.android.inputmethod.latin.makedict.DictionaryHeader;
+import com.android.inputmethod.latin.makedict.UnsupportedFormatException;
 import com.android.inputmethod.latin.personalization.PersonalizationHelper;
 
+import java.io.File;
+import java.io.IOException;
 import java.util.Locale;
 import java.util.Map;
 
@@ -39,6 +44,26 @@ public final class BinaryDictionaryUtils {
     private static native int editDistanceNative(int[] before, int[] after);
     private static native int setCurrentTimeForTestNative(int currentTime);
 
+    public static DictionaryHeader getHeader(final File dictFile)
+            throws IOException, UnsupportedFormatException {
+        return getHeaderWithOffsetAndLength(dictFile, 0 /* offset */, dictFile.length());
+    }
+
+    public static DictionaryHeader getHeaderWithOffsetAndLength(final File dictFile,
+            final long offset, final long length) throws IOException, UnsupportedFormatException {
+        // dictType is never used for reading the header. Passing an empty string.
+        final BinaryDictionary binaryDictionary = new BinaryDictionary(
+                dictFile.getAbsolutePath(), offset, length,
+                true /* useFullEditDistance */, null /* locale */, "" /* dictType */,
+                false /* isUpdatable */);
+        final DictionaryHeader header = binaryDictionary.getHeader();
+        binaryDictionary.close();
+        if (header == null) {
+            throw new IOException();
+        }
+        return header;
+    }
+
     public static boolean createEmptyDictFile(final String filePath, final long dictVersion,
             final Locale locale, final Map<String, String> attributeMap) {
         final String[] keyArray = new String[attributeMap.size()];
diff --git a/java/src/com/android/inputmethod/latin/utils/DictionaryInfoUtils.java b/java/src/com/android/inputmethod/latin/utils/DictionaryInfoUtils.java
index a1555651110380b91b494dbf1695f83b3d4d0612..e531d4b099a2d0bb886be75c93649a2874216c03 100644
--- a/java/src/com/android/inputmethod/latin/utils/DictionaryInfoUtils.java
+++ b/java/src/com/android/inputmethod/latin/utils/DictionaryInfoUtils.java
@@ -30,9 +30,11 @@ 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.DictionaryHeader;
+import com.android.inputmethod.latin.makedict.UnsupportedFormatException;
 import com.android.inputmethod.latin.settings.SpacingAndPunctuations;
 
 import java.io.File;
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.Locale;
@@ -283,7 +285,20 @@ public class DictionaryInfoUtils {
     }
 
     public static DictionaryHeader getDictionaryFileHeaderOrNull(final File file) {
-        return BinaryDictIOUtils.getDictionaryFileHeaderOrNull(file, 0, file.length());
+        return getDictionaryFileHeaderOrNull(file, 0, file.length());
+    }
+
+    private static DictionaryHeader getDictionaryFileHeaderOrNull(final File file,
+            final long offset, final long length) {
+        try {
+            final DictionaryHeader header =
+                    BinaryDictionaryUtils.getHeaderWithOffsetAndLength(file, offset, length);
+            return header;
+        } catch (UnsupportedFormatException e) {
+            return null;
+        } catch (IOException e) {
+            return null;
+        }
     }
 
     /**
@@ -294,7 +309,7 @@ public class DictionaryInfoUtils {
      */
     private static DictionaryInfo createDictionaryInfoFromFileAddress(
             final AssetFileAddress fileAddress) {
-        final DictionaryHeader header = BinaryDictIOUtils.getDictionaryFileHeaderOrNull(
+        final DictionaryHeader header = getDictionaryFileHeaderOrNull(
                 new File(fileAddress.mFilename), fileAddress.mOffset, fileAddress.mLength);
         if (header == null) {
             return null;