aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoder.java
diff options
context:
space:
mode:
authorKen Wakasa <kwakasa@google.com>2013-08-19 02:34:23 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2013-08-19 02:34:23 +0000
commita83e25642f1eae1412d85ce72f27601edd0ac10d (patch)
tree32d13d5b45981feb2206f0051d11df82ca08c657 /java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoder.java
parent8aaae56cf6694ec75043be56f1c7812a343b24d5 (diff)
parentd794b42f983a4f9563ef0334ed0b8f9cb44e084d (diff)
downloadlatinime-a83e25642f1eae1412d85ce72f27601edd0ac10d.tar.gz
latinime-a83e25642f1eae1412d85ce72f27601edd0ac10d.tar.xz
latinime-a83e25642f1eae1412d85ce72f27601edd0ac10d.zip
Merge "Add HeaderReaderInterface."
Diffstat (limited to 'java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoder.java')
-rw-r--r--java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoder.java28
1 files changed, 13 insertions, 15 deletions
diff --git a/java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoder.java b/java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoder.java
index 8d68c7ed6..5e3d6d22d 100644
--- a/java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoder.java
+++ b/java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoder.java
@@ -22,6 +22,7 @@ import com.android.inputmethod.latin.makedict.FormatSpec.FormatOptions;
import com.android.inputmethod.latin.makedict.FusionDictionary.CharGroup;
import com.android.inputmethod.latin.makedict.FusionDictionary.PtNodeArray;
import com.android.inputmethod.latin.makedict.FusionDictionary.WeightedString;
+import com.android.inputmethod.latin.makedict.decoder.HeaderReaderInterface;
import com.android.inputmethod.latin.utils.JniUtils;
import java.io.ByteArrayOutputStream;
@@ -250,7 +251,7 @@ public final class BinaryDictDecoder {
/**
* Reads a string from a buffer. This is the converse of the above method.
*/
- private static String readString(final FusionDictionaryBufferInterface buffer) {
+ static String readString(final FusionDictionaryBufferInterface buffer) {
final StringBuilder s = new StringBuilder();
int character = readChar(buffer);
while (character != FormatSpec.INVALID_CHARACTER) {
@@ -629,7 +630,7 @@ public final class BinaryDictDecoder {
* @throws UnsupportedFormatException
* @throws IOException
*/
- private static int checkFormatVersion(final FusionDictionaryBufferInterface buffer)
+ static int checkFormatVersion(final FusionDictionaryBufferInterface buffer)
throws IOException, UnsupportedFormatException {
final int version = getFormatVersion(buffer);
if (version < FormatSpec.MINIMUM_SUPPORTED_VERSION
@@ -643,25 +644,22 @@ public final class BinaryDictDecoder {
/**
* Reads a header from a buffer.
- * @param buffer the buffer to read.
+ * @param headerReader the header reader
* @throws IOException
* @throws UnsupportedFormatException
*/
- public static FileHeader readHeader(final FusionDictionaryBufferInterface buffer)
+ public static FileHeader readHeader(final HeaderReaderInterface headerReader)
throws IOException, UnsupportedFormatException {
- final int version = checkFormatVersion(buffer);
- final int optionsFlags = buffer.readUnsignedShort();
+ final int version = headerReader.readVersion();
+ final int optionsFlags = headerReader.readOptionFlags();
- final HashMap<String, String> attributes = new HashMap<String, String>();
- final int headerSize;
- headerSize = buffer.readInt();
+ final int headerSize = headerReader.readHeaderSize();
if (headerSize < 0) {
throw new UnsupportedFormatException("header size can't be negative.");
}
- populateOptions(buffer, headerSize, attributes);
- buffer.position(headerSize);
+ final HashMap<String, String> attributes = headerReader.readAttributes(headerSize);
final FileHeader header = new FileHeader(headerSize,
new FusionDictionary.DictionaryOptions(attributes,
@@ -711,14 +709,14 @@ public final class BinaryDictDecoder {
}
// Read header
- final FileHeader header = readHeader(reader.getBuffer());
+ final FileHeader fileHeader = readHeader(reader);
Map<Integer, PtNodeArray> reverseNodeArrayMapping = new TreeMap<Integer, PtNodeArray>();
Map<Integer, CharGroup> reverseGroupMapping = new TreeMap<Integer, CharGroup>();
- final PtNodeArray root = readNodeArray(reader.getBuffer(), header.mHeaderSize,
- reverseNodeArrayMapping, reverseGroupMapping, header.mFormatOptions);
+ final PtNodeArray root = readNodeArray(reader.getBuffer(), fileHeader.mHeaderSize,
+ reverseNodeArrayMapping, reverseGroupMapping, fileHeader.mFormatOptions);
- FusionDictionary newDict = new FusionDictionary(root, header.mDictionaryOptions);
+ FusionDictionary newDict = new FusionDictionary(root, fileHeader.mDictionaryOptions);
if (null != dict) {
for (final Word w : dict) {
if (w.mIsBlacklistEntry) {