aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/makedict/AbstractDictDecoder.java
diff options
context:
space:
mode:
authorJean Chalard <jchalard@google.com>2013-11-29 10:31:36 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2013-11-29 10:31:37 +0000
commitd7337a72bc27e77fd23fa47d5b9592dc8550ef74 (patch)
treef0900617555e02fb722d6945fd356e3935375c59 /java/src/com/android/inputmethod/latin/makedict/AbstractDictDecoder.java
parent3f8c1d4a19bc8b27e81c3ab898d9417db4a50c8a (diff)
parent26c9af33a77f5a1af38b12cfd09639530327e9e1 (diff)
downloadlatinime-d7337a72bc27e77fd23fa47d5b9592dc8550ef74.tar.gz
latinime-d7337a72bc27e77fd23fa47d5b9592dc8550ef74.tar.xz
latinime-d7337a72bc27e77fd23fa47d5b9592dc8550ef74.zip
Merge "Fix auto-detection of format 4."
Diffstat (limited to 'java/src/com/android/inputmethod/latin/makedict/AbstractDictDecoder.java')
-rw-r--r--java/src/com/android/inputmethod/latin/makedict/AbstractDictDecoder.java25
1 files changed, 25 insertions, 0 deletions
diff --git a/java/src/com/android/inputmethod/latin/makedict/AbstractDictDecoder.java b/java/src/com/android/inputmethod/latin/makedict/AbstractDictDecoder.java
index fda97dafc..b75fc37d9 100644
--- a/java/src/com/android/inputmethod/latin/makedict/AbstractDictDecoder.java
+++ b/java/src/com/android/inputmethod/latin/makedict/AbstractDictDecoder.java
@@ -32,6 +32,10 @@ import java.util.TreeMap;
* A base class of the binary dictionary decoder.
*/
public abstract class AbstractDictDecoder implements DictDecoder {
+ private static final int SUCCESS = 0;
+ private static final int ERROR_CANNOT_READ = 1;
+ private static final int ERROR_WRONG_FORMAT = 2;
+
protected FileHeader readHeader(final DictBuffer dictBuffer)
throws IOException, UnsupportedFormatException {
if (dictBuffer == null) {
@@ -204,4 +208,25 @@ public abstract class AbstractDictDecoder implements DictDecoder {
return readLength;
}
}
+
+ /**
+ * Check whether the header contains the expected information. This is a no-error method,
+ * that will return an error code and never throw a checked exception.
+ * @return an error code, either ERROR_* or SUCCESS.
+ */
+ private int checkHeader() {
+ try {
+ readHeader();
+ } catch (IOException e) {
+ return ERROR_CANNOT_READ;
+ } catch (UnsupportedFormatException e) {
+ return ERROR_WRONG_FORMAT;
+ }
+ return SUCCESS;
+ }
+
+ @Override
+ public boolean hasValidRawBinaryDictionary() {
+ return checkHeader() == SUCCESS;
+ }
}