Merge "Remove useless code (A12)" into jb-mr1-dev
diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java
index 9a888ad..9764df0 100644
--- a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java
+++ b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java
@@ -28,7 +28,7 @@
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
-import java.nio.ByteBuffer;
+import java.nio.BufferUnderflowException;
 import java.nio.channels.FileChannel;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -357,14 +357,15 @@
         try {
             // Read the version of the file
             inStream = new FileInputStream(f);
-            final ByteBuffer buffer = inStream.getChannel().map(
-                    FileChannel.MapMode.READ_ONLY, 0, f.length());
-            final int magic = buffer.getInt();
+            final BinaryDictInputOutput.ByteBufferWrapper buffer =
+                    new BinaryDictInputOutput.ByteBufferWrapper(inStream.getChannel().map(
+                            FileChannel.MapMode.READ_ONLY, 0, f.length()));
+            final int magic = buffer.readInt();
             if (magic != FormatSpec.VERSION_2_MAGIC_NUMBER) {
                 return false;
             }
-            final int formatVersion = buffer.getInt();
-            final int headerSize = buffer.getInt();
+            final int formatVersion = buffer.readInt();
+            final int headerSize = buffer.readInt();
             final HashMap<String, String> options = CollectionUtils.newHashMap();
             BinaryDictInputOutput.populateOptions(buffer, headerSize, options);
 
@@ -382,6 +383,8 @@
             return false;
         } catch (NumberFormatException e) {
             return false;
+        } catch (BufferUnderflowException e) {
+            return false;
         } finally {
             if (inStream != null) {
                 try {
diff --git a/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java b/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java
index 6f50869..68d8bc5 100644
--- a/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java
+++ b/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java
@@ -1543,11 +1543,6 @@
             options.put(key, value);
         }
     }
-    // TODO: remove this method.
-    public static void populateOptions(final ByteBuffer buffer, final int headerSize,
-            final HashMap<String, String> options) {
-        populateOptions(new ByteBufferWrapper(buffer), headerSize, options);
-    }
 
     /**
      * Reads a buffer and returns the memory representation of the dictionary.
diff --git a/java/src/com/android/inputmethod/latin/makedict/FusionDictionary.java b/java/src/com/android/inputmethod/latin/makedict/FusionDictionary.java
index 6775de8..98cf308 100644
--- a/java/src/com/android/inputmethod/latin/makedict/FusionDictionary.java
+++ b/java/src/com/android/inputmethod/latin/makedict/FusionDictionary.java
@@ -556,6 +556,7 @@
         final StringBuilder checker = DBG ? new StringBuilder() : null;
 
         CharGroup currentGroup;
+        final int codePointCountInS = s.codePointCount(0, s.length());
         do {
             int indexOfGroup = findIndexOfChar(node, s.codePointAt(index));
             if (CHARACTER_NOT_FOUND == indexOfGroup) return null;
@@ -570,12 +571,12 @@
             index = newIndex;
 
             if (DBG) checker.append(new String(currentGroup.mChars, 0, currentGroup.mChars.length));
-            if (index < s.length()) {
+            if (index < codePointCountInS) {
                 node = currentGroup.mChildren;
             }
-        } while (null != node && index < s.length());
+        } while (null != node && index < codePointCountInS);
 
-        if (index < s.length()) return null;
+        if (index < codePointCountInS) return null;
         if (!currentGroup.isTerminal()) return null;
         if (DBG && !s.equals(checker.toString())) return null;
         return currentGroup;