aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java
diff options
context:
space:
mode:
authorJean Chalard <jchalard@google.com>2012-08-19 22:14:42 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2012-08-19 22:14:42 -0700
commit6563ba3b28bc1be78542fa229e9a835c0c696e35 (patch)
treee394c87946fd19f35d525e4ab54d912ee798e233 /java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java
parent2b556f3303b96458868d78f7b652379408aca6c4 (diff)
parent7bf71ca8090208a14716bcbbab992a0d90764cfc (diff)
downloadlatinime-6563ba3b28bc1be78542fa229e9a835c0c696e35.tar.gz
latinime-6563ba3b28bc1be78542fa229e9a835c0c696e35.tar.xz
latinime-6563ba3b28bc1be78542fa229e9a835c0c696e35.zip
am 7bf71ca8: am 753f7b12: Merge "Hack to skip reading an outdated binary file." into jb-mr1-dev
* commit '7bf71ca8090208a14716bcbbab992a0d90764cfc': Hack to skip reading an outdated binary file.
Diffstat (limited to 'java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java')
-rw-r--r--java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java23
1 files changed, 17 insertions, 6 deletions
diff --git a/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java b/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java
index 7f042335a..b23b7db34 100644
--- a/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java
+++ b/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java
@@ -124,7 +124,7 @@ public class BinaryDictInputOutput {
*/
private static final int VERSION_1_MAGIC_NUMBER = 0x78B1;
- private static final int VERSION_2_MAGIC_NUMBER = 0x9BC13AFE;
+ public static final int VERSION_2_MAGIC_NUMBER = 0x9BC13AFE;
private static final int MINIMUM_SUPPORTED_VERSION = 1;
private static final int MAXIMUM_SUPPORTED_VERSION = 2;
private static final int NOT_A_VERSION_NUMBER = -1;
@@ -1328,6 +1328,21 @@ public class BinaryDictInputOutput {
}
/**
+ * Reads options from a file and populate a map with their contents.
+ *
+ * The file is read at the current file pointer, so the caller must take care the pointer
+ * is in the right place before calling this.
+ */
+ public static void populateOptionsFromFile(final RandomAccessFile source, final long headerSize,
+ final HashMap<String, String> options) throws IOException {
+ while (source.getFilePointer() < headerSize) {
+ final String key = CharEncoding.readString(source);
+ final String value = CharEncoding.readString(source);
+ options.put(key, value);
+ }
+ }
+
+ /**
* Reads a random access file and returns the memory representation of the dictionary.
*
* This high-level method takes a binary file and reads its contents, populating a
@@ -1358,11 +1373,7 @@ public class BinaryDictInputOutput {
} else {
headerSize = (source.readUnsignedByte() << 24) + (source.readUnsignedByte() << 16)
+ (source.readUnsignedByte() << 8) + source.readUnsignedByte();
- while (source.getFilePointer() < headerSize) {
- final String key = CharEncoding.readString(source);
- final String value = CharEncoding.readString(source);
- options.put(key, value);
- }
+ populateOptionsFromFile(source, headerSize, options);
source.seek(headerSize);
}