aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderUtils.java
diff options
context:
space:
mode:
authorJean Chalard <jchalard@google.com>2013-11-29 13:18:05 +0900
committerJean Chalard <jchalard@google.com>2013-11-29 19:10:19 +0900
commit26c9af33a77f5a1af38b12cfd09639530327e9e1 (patch)
treec8adc5e2eaa7e9793b8f2b10f7f9c5fb3f59d6f2 /java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderUtils.java
parentebd5541edfac105f7cf7b3e006695aa6fc6b903f (diff)
downloadlatinime-26c9af33a77f5a1af38b12cfd09639530327e9e1.tar.gz
latinime-26c9af33a77f5a1af38b12cfd09639530327e9e1.tar.xz
latinime-26c9af33a77f5a1af38b12cfd09639530327e9e1.zip
Fix auto-detection of format 4.
Bug: 11073222 Change-Id: I76e47d0399cf43fc3cc18cb1252f166be86b9a69
Diffstat (limited to 'java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderUtils.java')
-rw-r--r--java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderUtils.java27
1 files changed, 1 insertions, 26 deletions
diff --git a/java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderUtils.java b/java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderUtils.java
index 8a8ceaa8c..17c609fbe 100644
--- a/java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderUtils.java
+++ b/java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderUtils.java
@@ -24,12 +24,9 @@ import com.android.inputmethod.latin.makedict.FusionDictionary.PtNodeArray;
import com.android.inputmethod.latin.makedict.FusionDictionary.WeightedString;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.ByteBuffer;
-import java.nio.channels.FileChannel;
import java.util.ArrayList;
import java.util.Map;
import java.util.TreeMap;
@@ -639,32 +636,10 @@ public final class BinaryDictDecoderUtils {
/**
* Basic test to find out whether the file is a binary dictionary or not.
*
- * Concretely this only tests the magic number.
- *
* @param file The file to test.
* @return true if it's a binary dictionary, false otherwise
*/
public static boolean isBinaryDictionary(final File file) {
- FileInputStream inStream = null;
- try {
- inStream = new FileInputStream(file);
- final ByteBuffer buffer = inStream.getChannel().map(
- FileChannel.MapMode.READ_ONLY, 0, file.length());
- final int version = getFormatVersion(new ByteBufferDictBuffer(buffer));
- return (version >= FormatSpec.MINIMUM_SUPPORTED_VERSION
- && version <= FormatSpec.MAXIMUM_SUPPORTED_VERSION);
- } catch (FileNotFoundException e) {
- return false;
- } catch (IOException e) {
- return false;
- } finally {
- if (inStream != null) {
- try {
- inStream.close();
- } catch (IOException e) {
- // do nothing
- }
- }
- }
+ return FormatSpec.getDictDecoder(file).hasValidRawBinaryDictionary();
}
}