aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyboardView.java5
-rw-r--r--java/src/com/android/inputmethod/keyboard/PointerTracker.java9
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/PointerTrackerQueue.java4
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/PreviewPlacerView.java8
-rw-r--r--java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java3
-rw-r--r--java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java5
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java3
-rw-r--r--java/src/com/android/inputmethod/latin/RichInputConnection.java30
-rw-r--r--java/src/com/android/inputmethod/latin/UserHistoryDictIOUtils.java2
-rw-r--r--java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java436
-rw-r--r--java/src/com/android/inputmethod/latin/makedict/FormatSpec.java235
11 files changed, 413 insertions, 327 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java
index 27c3cc3e3..cf89567f8 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java
@@ -855,9 +855,10 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
}
@Override
- public void showGesturePreviewTrail(final PointerTracker tracker) {
+ public void showGesturePreviewTrail(final PointerTracker tracker,
+ final boolean isOldestTracker) {
locatePreviewPlacerView();
- mPreviewPlacerView.invalidatePointer(tracker);
+ mPreviewPlacerView.invalidatePointer(tracker, isOldestTracker);
}
@Override
diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java
index 4887ac557..e762b23c6 100644
--- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java
+++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java
@@ -80,7 +80,7 @@ public class PointerTracker implements PointerTrackerQueue.Element {
public void invalidateKey(Key key);
public void showKeyPreview(PointerTracker tracker);
public void dismissKeyPreview(PointerTracker tracker);
- public void showGesturePreviewTrail(PointerTracker tracker);
+ public void showGesturePreviewTrail(PointerTracker tracker, boolean isOldestTracker);
}
public interface TimerProxy {
@@ -550,7 +550,7 @@ public class PointerTracker implements PointerTrackerQueue.Element {
}
sInGesture = true;
mListener.onStartBatchInput();
- mDrawingProxy.showGesturePreviewTrail(this);
+ mDrawingProxy.showGesturePreviewTrail(this, true /* isOldestTracker */);
}
private void updateBatchInput(final long eventTime) {
@@ -567,7 +567,8 @@ public class PointerTracker implements PointerTrackerQueue.Element {
mListener.onUpdateBatchInput(sAggregratedPointers);
}
}
- mDrawingProxy.showGesturePreviewTrail(this);
+ final boolean isOldestTracker = sPointerTrackerQueue.getOldestElement() == this;
+ mDrawingProxy.showGesturePreviewTrail(this, isOldestTracker);
}
private void endBatchInput() {
@@ -584,7 +585,7 @@ public class PointerTracker implements PointerTrackerQueue.Element {
clearBatchInputPointsOfAllPointerTrackers();
}
}
- mDrawingProxy.showGesturePreviewTrail(this);
+ mDrawingProxy.showGesturePreviewTrail(this, true /* isOldestTracker */);
}
private static void abortBatchInput() {
diff --git a/java/src/com/android/inputmethod/keyboard/internal/PointerTrackerQueue.java b/java/src/com/android/inputmethod/keyboard/internal/PointerTrackerQueue.java
index e0858c019..c1a5cbead 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/PointerTrackerQueue.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/PointerTrackerQueue.java
@@ -73,6 +73,10 @@ public class PointerTrackerQueue {
mArraySize = newSize;
}
+ public synchronized Element getOldestElement() {
+ return (mArraySize == 0) ? null : mExpandableArrayOfActivePointers.get(0);
+ }
+
public synchronized void releaseAllPointersOlderThan(final Element pointer,
final long eventTime) {
if (DEBUG) {
diff --git a/java/src/com/android/inputmethod/keyboard/internal/PreviewPlacerView.java b/java/src/com/android/inputmethod/keyboard/internal/PreviewPlacerView.java
index 7104e3a12..3a850096f 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/PreviewPlacerView.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/PreviewPlacerView.java
@@ -188,7 +188,7 @@ public class PreviewPlacerView extends RelativeLayout {
mDrawsGestureFloatingPreviewText = drawsGestureFloatingPreviewText;
}
- public void invalidatePointer(final PointerTracker tracker) {
+ public void invalidatePointer(final PointerTracker tracker, final boolean isOldestTracker) {
GesturePreviewTrail trail;
synchronized (mGesturePreviewTrails) {
trail = mGesturePreviewTrails.get(tracker.mPointerId);
@@ -199,8 +199,10 @@ public class PreviewPlacerView extends RelativeLayout {
}
trail.addStroke(tracker.getGestureStrokeWithPreviewTrail(), tracker.getDownTime());
- mLastPointerX = tracker.getLastX();
- mLastPointerY = tracker.getLastY();
+ if (isOldestTracker) {
+ mLastPointerX = tracker.getLastX();
+ mLastPointerY = tracker.getLastY();
+ }
// TODO: Should narrow the invalidate region.
invalidate();
}
diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java
index e1cb195bc..9a888ade4 100644
--- a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java
+++ b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java
@@ -17,6 +17,7 @@
package com.android.inputmethod.latin;
import com.android.inputmethod.latin.makedict.BinaryDictInputOutput;
+import com.android.inputmethod.latin.makedict.FormatSpec;
import android.content.Context;
import android.content.SharedPreferences;
@@ -359,7 +360,7 @@ class BinaryDictionaryGetter {
final ByteBuffer buffer = inStream.getChannel().map(
FileChannel.MapMode.READ_ONLY, 0, f.length());
final int magic = buffer.getInt();
- if (magic != BinaryDictInputOutput.VERSION_2_MAGIC_NUMBER) {
+ if (magic != FormatSpec.VERSION_2_MAGIC_NUMBER) {
return false;
}
final int formatVersion = buffer.getInt();
diff --git a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java
index def978e4b..b93c17f11 100644
--- a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java
+++ b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java
@@ -21,6 +21,7 @@ import android.util.Log;
import com.android.inputmethod.keyboard.ProximityInfo;
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import com.android.inputmethod.latin.makedict.BinaryDictInputOutput;
+import com.android.inputmethod.latin.makedict.FormatSpec;
import com.android.inputmethod.latin.makedict.FusionDictionary;
import com.android.inputmethod.latin.makedict.FusionDictionary.Node;
import com.android.inputmethod.latin.makedict.FusionDictionary.WeightedString;
@@ -90,8 +91,8 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
private final DictionaryController mLocalDictionaryController = new DictionaryController();
private static final int BINARY_DICT_VERSION = 1;
- private static final BinaryDictInputOutput.FormatOptions FORMAT_OPTIONS =
- new BinaryDictInputOutput.FormatOptions(BINARY_DICT_VERSION);
+ private static final FormatSpec.FormatOptions FORMAT_OPTIONS =
+ new FormatSpec.FormatOptions(BINARY_DICT_VERSION);
/**
* Abstract method for loading the unigrams and bigrams of a given dictionary in a background
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index d8b1c292b..9194a977a 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -825,7 +825,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// we know for sure the cursor moved while we were composing and we should reset
// the state.
final boolean noComposingSpan = composingSpanStart == -1 && composingSpanEnd == -1;
- if (!mExpectingUpdateSelection) {
+ if (!mExpectingUpdateSelection
+ && !mConnection.isBelatedExpectedUpdate(oldSelStart, newSelStart)) {
// TAKE CARE: there is a race condition when we enter this test even when the user
// did not explicitly move the cursor. This happens when typing fast, where two keys
// turn this flag on in succession and both onUpdateSelection() calls arrive after
diff --git a/java/src/com/android/inputmethod/latin/RichInputConnection.java b/java/src/com/android/inputmethod/latin/RichInputConnection.java
index efda623e5..f77d6860e 100644
--- a/java/src/com/android/inputmethod/latin/RichInputConnection.java
+++ b/java/src/com/android/inputmethod/latin/RichInputConnection.java
@@ -642,4 +642,34 @@ public class RichInputConnection {
commitText(" " + textBeforeCursor.subSequence(0, 1), 1);
return true;
}
+
+ /**
+ * Heuristic to determine if this is an expected update of the cursor.
+ *
+ * Sometimes updates to the cursor position are late because of their asynchronous nature.
+ * This method tries to determine if this update is one, based on the values of the cursor
+ * position in the update, and the currently expected position of the cursor according to
+ * LatinIME's internal accounting. If this is not a belated expected update, then it should
+ * mean that the user moved the cursor explicitly.
+ * This is quite robust, but of course it's not perfect. In particular, it will fail in the
+ * case we get an update A, the user types in N characters so as to move the cursor to A+N but
+ * we don't get those, and then the user places the cursor between A and A+N, and we get only
+ * this update and not the ones in-between. This is almost impossible to achieve even trying
+ * very very hard.
+ *
+ * @param oldSelStart The value of the old cursor position in the update.
+ * @param newSelStart The value of the new cursor position in the update.
+ * @return whether this is a belated expected update or not.
+ */
+ public boolean isBelatedExpectedUpdate(final int oldSelStart, final int newSelStart) {
+ // If this is an update that arrives at our expected position, it's a belated update.
+ if (newSelStart == mCurrentCursorPosition) return true;
+ // If this is an update that moves the cursor from our expected position, it must be
+ // an explicit move.
+ if (oldSelStart == mCurrentCursorPosition) return false;
+ // The following returns true if newSelStart is between oldSelStart and
+ // mCurrentCursorPosition. We assume that if the updated position is between the old
+ // position and the expected position, then it must be a belated update.
+ return (newSelStart - oldSelStart) * (mCurrentCursorPosition - newSelStart) >= 0;
+ }
}
diff --git a/java/src/com/android/inputmethod/latin/UserHistoryDictIOUtils.java b/java/src/com/android/inputmethod/latin/UserHistoryDictIOUtils.java
index 1f5f1f7e6..550e4e58b 100644
--- a/java/src/com/android/inputmethod/latin/UserHistoryDictIOUtils.java
+++ b/java/src/com/android/inputmethod/latin/UserHistoryDictIOUtils.java
@@ -19,8 +19,8 @@ package com.android.inputmethod.latin;
import android.util.Log;
import com.android.inputmethod.latin.makedict.BinaryDictInputOutput;
-import com.android.inputmethod.latin.makedict.BinaryDictInputOutput.FormatOptions;
import com.android.inputmethod.latin.makedict.BinaryDictInputOutput.FusionDictionaryBufferInterface;
+import com.android.inputmethod.latin.makedict.FormatSpec.FormatOptions;
import com.android.inputmethod.latin.makedict.FusionDictionary;
import com.android.inputmethod.latin.makedict.FusionDictionary.Node;
import com.android.inputmethod.latin.makedict.PendingAttribute;
diff --git a/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java b/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java
index fbcb5eacc..ef10f7270 100644
--- a/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java
+++ b/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java
@@ -16,7 +16,8 @@
package com.android.inputmethod.latin.makedict;
-import com.android.inputmethod.latin.Constants;
+import com.android.inputmethod.latin.makedict.FormatSpec.FileHeader;
+import com.android.inputmethod.latin.makedict.FormatSpec.FormatOptions;
import com.android.inputmethod.latin.makedict.FusionDictionary.CharGroup;
import com.android.inputmethod.latin.makedict.FusionDictionary.DictionaryOptions;
import com.android.inputmethod.latin.makedict.FusionDictionary.Node;
@@ -47,177 +48,6 @@ public class BinaryDictInputOutput {
private static final boolean DBG = MakedictLog.DBG;
- /*
- * Array of Node(FusionDictionary.Node) layout is as follows:
- *
- * g |
- * r | the number of groups, 1 or 2 bytes.
- * o | 1 byte = bbbbbbbb match
- * u | case 1xxxxxxx => xxxxxxx << 8 + next byte
- * p | otherwise => bbbbbbbb
- * c |
- * ount
- *
- * g |
- * r | sequence of groups,
- * o | the layout of each group is described below.
- * u |
- * ps
- *
- */
-
- /* Node(CharGroup) layout is as follows:
- * | addressType xx : mask with MASK_GROUP_ADDRESS_TYPE
- * 2 bits, 00 = no children : FLAG_GROUP_ADDRESS_TYPE_NOADDRESS
- * f | 01 = 1 byte : FLAG_GROUP_ADDRESS_TYPE_ONEBYTE
- * l | 10 = 2 bytes : FLAG_GROUP_ADDRESS_TYPE_TWOBYTES
- * a | 11 = 3 bytes : FLAG_GROUP_ADDRESS_TYPE_THREEBYTES
- * g | has several chars ? 1 bit, 1 = yes, 0 = no : FLAG_HAS_MULTIPLE_CHARS
- * s | has a terminal ? 1 bit, 1 = yes, 0 = no : FLAG_IS_TERMINAL
- * | has shortcut targets ? 1 bit, 1 = yes, 0 = no : FLAG_HAS_SHORTCUT_TARGETS
- * | has bigrams ? 1 bit, 1 = yes, 0 = no : FLAG_HAS_BIGRAMS
- * | is not a word ? 1 bit, 1 = yes, 0 = no : FLAG_IS_NOT_A_WORD
- * | is blacklisted ? 1 bit, 1 = yes, 0 = no : FLAG_IS_BLACKLISTED
- *
- * p |
- * a | IF HAS_PARENT_ADDRESS (defined in the file header)
- * r | parent address, 3byte
- * e | the address must be negative, so the absolute value of the address is stored.
- * n |
- * taddress
- *
- * c | IF FLAG_HAS_MULTIPLE_CHARS
- * h | char, char, char, char n * (1 or 3 bytes) : use CharGroupInfo for i/o helpers
- * a | end 1 byte, = 0
- * r | ELSE
- * s | char 1 or 3 bytes
- * | END
- *
- * f |
- * r | IF FLAG_IS_TERMINAL
- * e | frequency 1 byte
- * q |
- *
- * c | IF 00 = FLAG_GROUP_ADDRESS_TYPE_NOADDRESS = addressType
- * h | // nothing
- * i | ELSIF 01 = FLAG_GROUP_ADDRESS_TYPE_ONEBYTE == addressType
- * l | children address, 1 byte
- * d | ELSIF 10 = FLAG_GROUP_ADDRESS_TYPE_TWOBYTES == addressType
- * r | children address, 2 bytes
- * e | ELSE // 11 = FLAG_GROUP_ADDRESS_TYPE_THREEBYTES = addressType
- * n | children address, 3 bytes
- * A | END
- * d
- * dress
- *
- * | IF FLAG_IS_TERMINAL && FLAG_HAS_SHORTCUT_TARGETS
- * | shortcut string list
- * | IF FLAG_IS_TERMINAL && FLAG_HAS_BIGRAMS
- * | bigrams address list
- *
- * Char format is:
- * 1 byte = bbbbbbbb match
- * case 000xxxxx: xxxxx << 16 + next byte << 8 + next byte
- * else: if 00011111 (= 0x1F) : this is the terminator. This is a relevant choice because
- * unicode code points range from 0 to 0x10FFFF, so any 3-byte value starting with
- * 00011111 would be outside unicode.
- * else: iso-latin-1 code
- * This allows for the whole unicode range to be encoded, including chars outside of
- * the BMP. Also everything in the iso-latin-1 charset is only 1 byte, except control
- * characters which should never happen anyway (and still work, but take 3 bytes).
- *
- * bigram address list is:
- * <flags> = | hasNext = 1 bit, 1 = yes, 0 = no : FLAG_ATTRIBUTE_HAS_NEXT
- * | addressSign = 1 bit, : FLAG_ATTRIBUTE_OFFSET_NEGATIVE
- * | 1 = must take -address, 0 = must take +address
- * | xx : mask with MASK_ATTRIBUTE_ADDRESS_TYPE
- * | addressFormat = 2 bits, 00 = unused : FLAG_ATTRIBUTE_ADDRESS_TYPE_ONEBYTE
- * | 01 = 1 byte : FLAG_ATTRIBUTE_ADDRESS_TYPE_ONEBYTE
- * | 10 = 2 bytes : FLAG_ATTRIBUTE_ADDRESS_TYPE_TWOBYTES
- * | 11 = 3 bytes : FLAG_ATTRIBUTE_ADDRESS_TYPE_THREEBYTES
- * | 4 bits : frequency : mask with FLAG_ATTRIBUTE_FREQUENCY
- * <address> | IF (01 == FLAG_ATTRIBUTE_ADDRESS_TYPE_ONEBYTE == addressFormat)
- * | read 1 byte, add top 4 bits
- * | ELSIF (10 == FLAG_ATTRIBUTE_ADDRESS_TYPE_TWOBYTES == addressFormat)
- * | read 2 bytes, add top 4 bits
- * | ELSE // 11 == FLAG_ATTRIBUTE_ADDRESS_TYPE_THREEBYTES == addressFormat
- * | read 3 bytes, add top 4 bits
- * | END
- * | if (FLAG_ATTRIBUTE_OFFSET_NEGATIVE) then address = -address
- * if (FLAG_ATTRIBUTE_HAS_NEXT) goto bigram_and_shortcut_address_list_is
- *
- * shortcut string list is:
- * <byte size> = GROUP_SHORTCUT_LIST_SIZE_SIZE bytes, big-endian: size of the list, in bytes.
- * <flags> = | hasNext = 1 bit, 1 = yes, 0 = no : FLAG_ATTRIBUTE_HAS_NEXT
- * | reserved = 3 bits, must be 0
- * | 4 bits : frequency : mask with FLAG_ATTRIBUTE_FREQUENCY
- * <shortcut> = | string of characters at the char format described above, with the terminator
- * | used to signal the end of the string.
- * if (FLAG_ATTRIBUTE_HAS_NEXT goto flags
- */
-
- private static final int VERSION_1_MAGIC_NUMBER = 0x78B1;
- public static final int VERSION_2_MAGIC_NUMBER = 0x9BC13AFE;
- private static final int MINIMUM_SUPPORTED_VERSION = 1;
- private static final int MAXIMUM_SUPPORTED_VERSION = 3;
- private static final int NOT_A_VERSION_NUMBER = -1;
- private static final int FIRST_VERSION_WITH_HEADER_SIZE = 2;
- private static final int FIRST_VERSION_WITH_PARENT_ADDRESS = 3;
-
- // These options need to be the same numeric values as the one in the native reading code.
- private static final int GERMAN_UMLAUT_PROCESSING_FLAG = 0x1;
- private static final int HAS_PARENT_ADDRESS = 0x2;
- private static final int FRENCH_LIGATURE_PROCESSING_FLAG = 0x4;
- private static final int CONTAINS_BIGRAMS_FLAG = 0x8;
-
- // TODO: Make this value adaptative to content data, store it in the header, and
- // use it in the reading code.
- private static final int MAX_WORD_LENGTH = Constants.Dictionary.MAX_WORD_LENGTH;
-
- private static final int PARENT_ADDRESS_SIZE = 3;
-
- private static final int MASK_GROUP_ADDRESS_TYPE = 0xC0;
- private static final int FLAG_GROUP_ADDRESS_TYPE_NOADDRESS = 0x00;
- private static final int FLAG_GROUP_ADDRESS_TYPE_ONEBYTE = 0x40;
- private static final int FLAG_GROUP_ADDRESS_TYPE_TWOBYTES = 0x80;
- private static final int FLAG_GROUP_ADDRESS_TYPE_THREEBYTES = 0xC0;
-
- private static final int FLAG_HAS_MULTIPLE_CHARS = 0x20;
-
- private static final int FLAG_IS_TERMINAL = 0x10;
- private static final int FLAG_HAS_SHORTCUT_TARGETS = 0x08;
- private static final int FLAG_HAS_BIGRAMS = 0x04;
- private static final int FLAG_IS_NOT_A_WORD = 0x02;
- private static final int FLAG_IS_BLACKLISTED = 0x01;
-
- private static final int FLAG_ATTRIBUTE_HAS_NEXT = 0x80;
- private static final int FLAG_ATTRIBUTE_OFFSET_NEGATIVE = 0x40;
- private static final int MASK_ATTRIBUTE_ADDRESS_TYPE = 0x30;
- private static final int FLAG_ATTRIBUTE_ADDRESS_TYPE_ONEBYTE = 0x10;
- private static final int FLAG_ATTRIBUTE_ADDRESS_TYPE_TWOBYTES = 0x20;
- private static final int FLAG_ATTRIBUTE_ADDRESS_TYPE_THREEBYTES = 0x30;
- private static final int FLAG_ATTRIBUTE_FREQUENCY = 0x0F;
-
- private static final int GROUP_CHARACTERS_TERMINATOR = 0x1F;
-
- private static final int GROUP_TERMINATOR_SIZE = 1;
- private static final int GROUP_FLAGS_SIZE = 1;
- private static final int GROUP_FREQUENCY_SIZE = 1;
- private static final int GROUP_MAX_ADDRESS_SIZE = 3;
- private static final int GROUP_ATTRIBUTE_FLAGS_SIZE = 1;
- private static final int GROUP_ATTRIBUTE_MAX_ADDRESS_SIZE = 3;
- private static final int GROUP_SHORTCUT_LIST_SIZE_SIZE = 2;
-
- private static final int NO_CHILDREN_ADDRESS = Integer.MIN_VALUE;
- private static final int NO_PARENT_ADDRESS = 0;
- private static final int INVALID_CHARACTER = -1;
-
- private static final int MAX_CHARGROUPS_FOR_ONE_BYTE_CHARGROUP_COUNT = 0x7F; // 127
- private static final int MAX_CHARGROUPS_IN_A_NODE = 0x7FFF; // 32767
-
- private static final int MAX_TERMINAL_FREQUENCY = 255;
- private static final int MAX_BIGRAM_FREQUENCY = 15;
-
// Arbitrary limit to how much passes we consider address size compression should
// terminate in. At the time of this writing, our largest dictionary completes
// compression in five passes.
@@ -280,40 +110,6 @@ public class BinaryDictInputOutput {
}
/**
- * Options about file format.
- */
- public static class FormatOptions {
- public final int mVersion;
- public final boolean mHasParentAddress;
- public FormatOptions(final int version) {
- this(version, false);
- }
- public FormatOptions(final int version, final boolean hasParentAddress) {
- mVersion = version;
- if (version < FIRST_VERSION_WITH_PARENT_ADDRESS && hasParentAddress) {
- throw new RuntimeException("Parent addresses are only supported with versions "
- + FIRST_VERSION_WITH_PARENT_ADDRESS + " and ulterior.");
- }
- mHasParentAddress = hasParentAddress;
- }
- }
-
- /**
- * Class representing file header.
- */
- private static final class FileHeader {
- public final int mHeaderSize;
- public final DictionaryOptions mDictionaryOptions;
- public final FormatOptions mFormatOptions;
- public FileHeader(final int headerSize, final DictionaryOptions dictionaryOptions,
- final FormatOptions formatOptions) {
- mHeaderSize = headerSize;
- mDictionaryOptions = dictionaryOptions;
- mFormatOptions = formatOptions;
- }
- }
-
- /**
* A class grouping utility function for our specific character encoding.
*/
private static class CharEncoding {
@@ -349,7 +145,7 @@ public class BinaryDictInputOutput {
private static int getCharSize(final int character) {
// See char encoding in FusionDictionary.java
if (fitsOnOneByte(character)) return 1;
- if (INVALID_CHARACTER == character) return 1;
+ if (FormatSpec.INVALID_CHARACTER == character) return 1;
return 3;
}
@@ -407,7 +203,7 @@ public class BinaryDictInputOutput {
buffer[index++] = (byte)(0xFF & codePoint);
}
}
- buffer[index++] = GROUP_CHARACTERS_TERMINATOR;
+ buffer[index++] = FormatSpec.GROUP_CHARACTERS_TERMINATOR;
return index - origin;
}
@@ -431,7 +227,7 @@ public class BinaryDictInputOutput {
buffer.write((byte) (0xFF & codePoint));
}
}
- buffer.write(GROUP_CHARACTERS_TERMINATOR);
+ buffer.write(FormatSpec.GROUP_CHARACTERS_TERMINATOR);
}
/**
@@ -440,7 +236,7 @@ public class BinaryDictInputOutput {
private static String readString(final FusionDictionaryBufferInterface buffer) {
final StringBuilder s = new StringBuilder();
int character = readChar(buffer);
- while (character != INVALID_CHARACTER) {
+ while (character != FormatSpec.INVALID_CHARACTER) {
s.appendCodePoint(character);
character = readChar(buffer);
}
@@ -458,7 +254,9 @@ public class BinaryDictInputOutput {
private static int readChar(final FusionDictionaryBufferInterface buffer) {
int character = buffer.readUnsignedByte();
if (!fitsOnOneByte(character)) {
- if (GROUP_CHARACTERS_TERMINATOR == character) return INVALID_CHARACTER;
+ if (FormatSpec.GROUP_CHARACTERS_TERMINATOR == character) {
+ return FormatSpec.INVALID_CHARACTER;
+ }
character <<= 16;
character += buffer.readUnsignedShort();
}
@@ -477,7 +275,7 @@ public class BinaryDictInputOutput {
*/
private static int getGroupCharactersSize(final CharGroup group) {
int size = CharEncoding.getCharArraySize(group.mChars);
- if (group.hasSeveralChars()) size += GROUP_TERMINATOR_SIZE;
+ if (group.hasSeveralChars()) size += FormatSpec.GROUP_TERMINATOR_SIZE;
return size;
}
@@ -487,13 +285,14 @@ public class BinaryDictInputOutput {
* @return the size of the group count, either 1 or 2 bytes.
*/
private static int getGroupCountSize(final int count) {
- if (MAX_CHARGROUPS_FOR_ONE_BYTE_CHARGROUP_COUNT >= count) {
+ if (FormatSpec.MAX_CHARGROUPS_FOR_ONE_BYTE_CHARGROUP_COUNT >= count) {
return 1;
- } else if (MAX_CHARGROUPS_IN_A_NODE >= count) {
+ } else if (FormatSpec.MAX_CHARGROUPS_IN_A_NODE >= count) {
return 2;
} else {
- throw new RuntimeException("Can't have more than " + MAX_CHARGROUPS_IN_A_NODE
- + " groups in a node (found " + count + ")");
+ throw new RuntimeException("Can't have more than "
+ + FormatSpec.MAX_CHARGROUPS_IN_A_NODE + " groups in a node (found " + count
+ + ")");
}
}
@@ -510,14 +309,14 @@ public class BinaryDictInputOutput {
* Compute the size of a shortcut in bytes.
*/
private static int getShortcutSize(final WeightedString shortcut) {
- int size = GROUP_ATTRIBUTE_FLAGS_SIZE;
+ int size = FormatSpec.GROUP_ATTRIBUTE_FLAGS_SIZE;
final String word = shortcut.mWord;
final int length = word.length();
for (int i = 0; i < length; i = word.offsetByCodePoints(i, 1)) {
final int codePoint = word.codePointAt(i);
size += CharEncoding.getCharSize(codePoint);
}
- size += GROUP_TERMINATOR_SIZE;
+ size += FormatSpec.GROUP_TERMINATOR_SIZE;
return size;
}
@@ -529,7 +328,7 @@ public class BinaryDictInputOutput {
*/
private static int getShortcutListSize(final ArrayList<WeightedString> shortcutList) {
if (null == shortcutList) return 0;
- int size = GROUP_SHORTCUT_LIST_SIZE_SIZE;
+ int size = FormatSpec.GROUP_SHORTCUT_LIST_SIZE_SIZE;
for (final WeightedString shortcut : shortcutList) {
size += getShortcutSize(shortcut);
}
@@ -546,11 +345,12 @@ public class BinaryDictInputOutput {
private static int getCharGroupMaximumSize(final CharGroup group, final FormatOptions options) {
int size = getGroupHeaderSize(group, options);
// If terminal, one byte for the frequency
- if (group.isTerminal()) size += GROUP_FREQUENCY_SIZE;
- size += GROUP_MAX_ADDRESS_SIZE; // For children address
+ if (group.isTerminal()) size += FormatSpec.GROUP_FREQUENCY_SIZE;
+ size += FormatSpec.GROUP_MAX_ADDRESS_SIZE; // For children address
size += getShortcutListSize(group.mShortcutTargets);
if (null != group.mBigrams) {
- size += (GROUP_ATTRIBUTE_FLAGS_SIZE + GROUP_ATTRIBUTE_MAX_ADDRESS_SIZE)
+ size += (FormatSpec.GROUP_ATTRIBUTE_FLAGS_SIZE
+ + FormatSpec.GROUP_ATTRIBUTE_MAX_ADDRESS_SIZE)
* group.mBigrams.size();
}
return size;
@@ -577,14 +377,14 @@ public class BinaryDictInputOutput {
* Helper method to hide the actual value of the no children address.
*/
private static boolean hasChildrenAddress(final int address) {
- return NO_CHILDREN_ADDRESS != address;
+ return FormatSpec.NO_CHILDREN_ADDRESS != address;
}
/**
* Helper method to check whether the CharGroup has a parent address.
*/
private static boolean hasParentAddress(final FormatOptions options) {
- return options.mVersion >= FIRST_VERSION_WITH_PARENT_ADDRESS
+ return options.mVersion >= FormatSpec.FIRST_VERSION_WITH_PARENT_ADDRESS
&& options.mHasParentAddress;
}
@@ -596,9 +396,10 @@ public class BinaryDictInputOutput {
*/
private static int getGroupHeaderSize(final CharGroup group, final FormatOptions options) {
if (hasParentAddress(options)) {
- return GROUP_FLAGS_SIZE + PARENT_ADDRESS_SIZE + getGroupCharactersSize(group);
+ return FormatSpec.GROUP_FLAGS_SIZE + FormatSpec.PARENT_ADDRESS_SIZE
+ + getGroupCharactersSize(group);
} else {
- return GROUP_FLAGS_SIZE + getGroupCharactersSize(group);
+ return FormatSpec.GROUP_FLAGS_SIZE + getGroupCharactersSize(group);
}
}
@@ -698,7 +499,7 @@ public class BinaryDictInputOutput {
group.mCachedAddress = node.mCachedAddress + size;
}
int groupSize = getGroupHeaderSize(group, formatOptions);
- if (group.isTerminal()) groupSize += GROUP_FREQUENCY_SIZE;
+ if (group.isTerminal()) groupSize += FormatSpec.GROUP_FREQUENCY_SIZE;
if (null != group.mChildren) {
final int offsetBasePoint = groupSize + node.mCachedAddress + size;
final int offset = group.mChildren.mCachedAddress - offsetBasePoint;
@@ -711,10 +512,10 @@ public class BinaryDictInputOutput {
if (null != group.mBigrams) {
for (WeightedString bigram : group.mBigrams) {
final int offsetBasePoint = groupSize + node.mCachedAddress + size
- + GROUP_FLAGS_SIZE;
+ + FormatSpec.GROUP_FLAGS_SIZE;
final int addressOfBigram = findAddressOfWord(dict, bigram.mWord);
final int offset = addressOfBigram - offsetBasePoint;
- groupSize += getByteSize(offset) + GROUP_FLAGS_SIZE;
+ groupSize += getByteSize(offset) + FormatSpec.GROUP_FLAGS_SIZE;
}
}
group.mCachedSize = groupSize;
@@ -854,20 +655,20 @@ public class BinaryDictInputOutput {
private static byte makeCharGroupFlags(final CharGroup group, final int groupAddress,
final int childrenOffset) {
byte flags = 0;
- if (group.mChars.length > 1) flags |= FLAG_HAS_MULTIPLE_CHARS;
+ if (group.mChars.length > 1) flags |= FormatSpec.FLAG_HAS_MULTIPLE_CHARS;
if (group.mFrequency >= 0) {
- flags |= FLAG_IS_TERMINAL;
+ flags |= FormatSpec.FLAG_IS_TERMINAL;
}
if (null != group.mChildren) {
switch (getByteSize(childrenOffset)) {
case 1:
- flags |= FLAG_GROUP_ADDRESS_TYPE_ONEBYTE;
+ flags |= FormatSpec.FLAG_GROUP_ADDRESS_TYPE_ONEBYTE;
break;
case 2:
- flags |= FLAG_GROUP_ADDRESS_TYPE_TWOBYTES;
+ flags |= FormatSpec.FLAG_GROUP_ADDRESS_TYPE_TWOBYTES;
break;
case 3:
- flags |= FLAG_GROUP_ADDRESS_TYPE_THREEBYTES;
+ flags |= FormatSpec.FLAG_GROUP_ADDRESS_TYPE_THREEBYTES;
break;
default:
throw new RuntimeException("Node with a strange address");
@@ -877,19 +678,19 @@ public class BinaryDictInputOutput {
if (DBG && 0 == group.mShortcutTargets.size()) {
throw new RuntimeException("0-sized shortcut list must be null");
}
- flags |= FLAG_HAS_SHORTCUT_TARGETS;
+ flags |= FormatSpec.FLAG_HAS_SHORTCUT_TARGETS;
}
if (null != group.mBigrams) {
if (DBG && 0 == group.mBigrams.size()) {
throw new RuntimeException("0-sized bigram list must be null");
}
- flags |= FLAG_HAS_BIGRAMS;
+ flags |= FormatSpec.FLAG_HAS_BIGRAMS;
}
if (group.mIsNotAWord) {
- flags |= FLAG_IS_NOT_A_WORD;
+ flags |= FormatSpec.FLAG_IS_NOT_A_WORD;
}
if (group.mIsBlacklistEntry) {
- flags |= FLAG_IS_BLACKLISTED;
+ flags |= FormatSpec.FLAG_IS_BLACKLISTED;
}
return flags;
}
@@ -906,17 +707,17 @@ public class BinaryDictInputOutput {
*/
private static final int makeBigramFlags(final boolean more, final int offset,
int bigramFrequency, final int unigramFrequency, final String word) {
- int bigramFlags = (more ? FLAG_ATTRIBUTE_HAS_NEXT : 0)
- + (offset < 0 ? FLAG_ATTRIBUTE_OFFSET_NEGATIVE : 0);
+ int bigramFlags = (more ? FormatSpec.FLAG_ATTRIBUTE_HAS_NEXT : 0)
+ + (offset < 0 ? FormatSpec.FLAG_ATTRIBUTE_OFFSET_NEGATIVE : 0);
switch (getByteSize(offset)) {
case 1:
- bigramFlags |= FLAG_ATTRIBUTE_ADDRESS_TYPE_ONEBYTE;
+ bigramFlags |= FormatSpec.FLAG_ATTRIBUTE_ADDRESS_TYPE_ONEBYTE;
break;
case 2:
- bigramFlags |= FLAG_ATTRIBUTE_ADDRESS_TYPE_TWOBYTES;
+ bigramFlags |= FormatSpec.FLAG_ATTRIBUTE_ADDRESS_TYPE_TWOBYTES;
break;
case 3:
- bigramFlags |= FLAG_ATTRIBUTE_ADDRESS_TYPE_THREEBYTES;
+ bigramFlags |= FormatSpec.FLAG_ATTRIBUTE_ADDRESS_TYPE_THREEBYTES;
break;
default:
throw new RuntimeException("Strange offset size");
@@ -951,7 +752,8 @@ public class BinaryDictInputOutput {
// approximation. (0.5 to get the first step start, and 0.5 to get the middle of the
// step pointed by the discretized frequency.
final float stepSize =
- (MAX_TERMINAL_FREQUENCY - unigramFrequency) / (1.5f + MAX_BIGRAM_FREQUENCY);
+ (FormatSpec.MAX_TERMINAL_FREQUENCY - unigramFrequency)
+ / (1.5f + FormatSpec.MAX_BIGRAM_FREQUENCY);
final float firstStepStart = 1 + unigramFrequency + (stepSize / 2.0f);
final int discretizedFrequency = (int)((bigramFrequency - firstStepStart) / stepSize);
// If the bigram freq is less than half-a-step higher than the unigram freq, we get -1
@@ -960,7 +762,7 @@ public class BinaryDictInputOutput {
// small over-estimation that we get in this case. TODO: actually remove this bigram
// if discretizedFrequency < 0.
final int finalBigramFrequency = discretizedFrequency > 0 ? discretizedFrequency : 0;
- bigramFlags += finalBigramFrequency & FLAG_ATTRIBUTE_FREQUENCY;
+ bigramFlags += finalBigramFrequency & FormatSpec.FLAG_ATTRIBUTE_FREQUENCY;
return bigramFlags;
}
@@ -971,10 +773,10 @@ public class BinaryDictInputOutput {
final FormatOptions formatOptions) {
final DictionaryOptions options = dictionary.mOptions;
final boolean hasBigrams = dictionary.hasBigrams();
- return (options.mFrenchLigatureProcessing ? FRENCH_LIGATURE_PROCESSING_FLAG : 0)
- + (options.mGermanUmlautProcessing ? GERMAN_UMLAUT_PROCESSING_FLAG : 0)
- + (hasBigrams ? CONTAINS_BIGRAMS_FLAG : 0)
- + (formatOptions.mHasParentAddress ? HAS_PARENT_ADDRESS : 0);
+ return (options.mFrenchLigatureProcessing ? FormatSpec.FRENCH_LIGATURE_PROCESSING_FLAG : 0)
+ + (options.mGermanUmlautProcessing ? FormatSpec.GERMAN_UMLAUT_PROCESSING_FLAG : 0)
+ + (hasBigrams ? FormatSpec.CONTAINS_BIGRAMS_FLAG : 0)
+ + (formatOptions.mHasParentAddress ? FormatSpec.HAS_PARENT_ADDRESS : 0);
}
/**
@@ -985,7 +787,8 @@ public class BinaryDictInputOutput {
* @return the flags
*/
private static final int makeShortcutFlags(final boolean more, final int frequency) {
- return (more ? FLAG_ATTRIBUTE_HAS_NEXT : 0) + (frequency & FLAG_ATTRIBUTE_FREQUENCY);
+ return (more ? FormatSpec.FLAG_ATTRIBUTE_HAS_NEXT : 0)
+ + (frequency & FormatSpec.FLAG_ATTRIBUTE_FREQUENCY);
}
/**
@@ -1025,18 +828,20 @@ public class BinaryDictInputOutput {
+ index + " <> " + group.mCachedAddress);
groupAddress += getGroupHeaderSize(group, formatOptions);
// Sanity checks.
- if (DBG && group.mFrequency > MAX_TERMINAL_FREQUENCY) {
- throw new RuntimeException("A node has a frequency > " + MAX_TERMINAL_FREQUENCY
+ if (DBG && group.mFrequency > FormatSpec.MAX_TERMINAL_FREQUENCY) {
+ throw new RuntimeException("A node has a frequency > "
+ + FormatSpec.MAX_TERMINAL_FREQUENCY
+ " : " + group.mFrequency);
}
- if (group.mFrequency >= 0) groupAddress += GROUP_FREQUENCY_SIZE;
+ if (group.mFrequency >= 0) groupAddress += FormatSpec.GROUP_FREQUENCY_SIZE;
final int childrenOffset = null == group.mChildren
- ? NO_CHILDREN_ADDRESS : group.mChildren.mCachedAddress - groupAddress;
+ ? FormatSpec.NO_CHILDREN_ADDRESS
+ : group.mChildren.mCachedAddress - groupAddress;
byte flags = makeCharGroupFlags(group, groupAddress, childrenOffset);
buffer[index++] = flags;
if (hasParentAddress(formatOptions)) {
- if (parentAddress == NO_PARENT_ADDRESS) {
+ if (parentAddress == FormatSpec.NO_PARENT_ADDRESS) {
// this node is the root node.
buffer[index] = buffer[index + 1] = buffer[index + 2] = 0;
} else {
@@ -1052,7 +857,7 @@ public class BinaryDictInputOutput {
index = CharEncoding.writeCharArray(group.mChars, buffer, index);
if (group.hasSeveralChars()) {
- buffer[index++] = GROUP_CHARACTERS_TERMINATOR;
+ buffer[index++] = FormatSpec.GROUP_CHARACTERS_TERMINATOR;
}
if (group.mFrequency >= 0) {
buffer[index++] = (byte) group.mFrequency;
@@ -1064,8 +869,8 @@ public class BinaryDictInputOutput {
// Write shortcuts
if (null != group.mShortcutTargets) {
final int indexOfShortcutByteSize = index;
- index += GROUP_SHORTCUT_LIST_SIZE_SIZE;
- groupAddress += GROUP_SHORTCUT_LIST_SIZE_SIZE;
+ index += FormatSpec.GROUP_SHORTCUT_LIST_SIZE_SIZE;
+ groupAddress += FormatSpec.GROUP_SHORTCUT_LIST_SIZE_SIZE;
final Iterator<WeightedString> shortcutIterator = group.mShortcutTargets.iterator();
while (shortcutIterator.hasNext()) {
final WeightedString target = shortcutIterator.next();
@@ -1187,28 +992,30 @@ public class BinaryDictInputOutput {
// parents. As long as this is ensured, the dictionary file may grow to any size.
final int version = formatOptions.mVersion;
- if (version < MINIMUM_SUPPORTED_VERSION || version > MAXIMUM_SUPPORTED_VERSION) {
+ if (version < FormatSpec.MINIMUM_SUPPORTED_VERSION
+ || version > FormatSpec.MAXIMUM_SUPPORTED_VERSION) {
throw new UnsupportedFormatException("Requested file format version " + version
+ ", but this implementation only supports versions "
- + MINIMUM_SUPPORTED_VERSION + " through " + MAXIMUM_SUPPORTED_VERSION);
+ + FormatSpec.MINIMUM_SUPPORTED_VERSION + " through "
+ + FormatSpec.MAXIMUM_SUPPORTED_VERSION);
}
ByteArrayOutputStream headerBuffer = new ByteArrayOutputStream(256);
// The magic number in big-endian order.
- if (version >= FIRST_VERSION_WITH_HEADER_SIZE) {
+ if (version >= FormatSpec.FIRST_VERSION_WITH_HEADER_SIZE) {
// Magic number for version 2+.
- headerBuffer.write((byte) (0xFF & (VERSION_2_MAGIC_NUMBER >> 24)));
- headerBuffer.write((byte) (0xFF & (VERSION_2_MAGIC_NUMBER >> 16)));
- headerBuffer.write((byte) (0xFF & (VERSION_2_MAGIC_NUMBER >> 8)));
- headerBuffer.write((byte) (0xFF & VERSION_2_MAGIC_NUMBER));
+ headerBuffer.write((byte) (0xFF & (FormatSpec.VERSION_2_MAGIC_NUMBER >> 24)));
+ headerBuffer.write((byte) (0xFF & (FormatSpec.VERSION_2_MAGIC_NUMBER >> 16)));
+ headerBuffer.write((byte) (0xFF & (FormatSpec.VERSION_2_MAGIC_NUMBER >> 8)));
+ headerBuffer.write((byte) (0xFF & FormatSpec.VERSION_2_MAGIC_NUMBER));
// Dictionary version.
headerBuffer.write((byte) (0xFF & (version >> 8)));
headerBuffer.write((byte) (0xFF & version));
} else {
// Magic number for version 1.
- headerBuffer.write((byte) (0xFF & (VERSION_1_MAGIC_NUMBER >> 8)));
- headerBuffer.write((byte) (0xFF & VERSION_1_MAGIC_NUMBER));
+ headerBuffer.write((byte) (0xFF & (FormatSpec.VERSION_1_MAGIC_NUMBER >> 8)));
+ headerBuffer.write((byte) (0xFF & FormatSpec.VERSION_1_MAGIC_NUMBER));
// Dictionary version.
headerBuffer.write((byte) (0xFF & version));
}
@@ -1216,7 +1023,7 @@ public class BinaryDictInputOutput {
final int options = makeOptionsValue(dict, formatOptions);
headerBuffer.write((byte) (0xFF & (options >> 8)));
headerBuffer.write((byte) (0xFF & options));
- if (version >= FIRST_VERSION_WITH_HEADER_SIZE) {
+ if (version >= FormatSpec.FIRST_VERSION_WITH_HEADER_SIZE) {
final int headerSizeOffset = headerBuffer.size();
// Placeholder to be written later with header size.
for (int i = 0; i < 4; ++i) {
@@ -1275,7 +1082,7 @@ public class BinaryDictInputOutput {
// Input methods: Read a binary dictionary to memory.
// readDictionaryBinary is the public entry point for them.
- private static final int[] CHARACTER_BUFFER = new int[MAX_WORD_LENGTH];
+ private static final int[] CHARACTER_BUFFER = new int[FormatSpec.MAX_WORD_LENGTH];
private static CharGroupInfo readCharGroup(final FusionDictionaryBufferInterface buffer,
final int originalGroupAddress, final FormatOptions options) {
int addressPointer = originalGroupAddress;
@@ -1288,11 +1095,11 @@ public class BinaryDictInputOutput {
parentAddress = -buffer.readUnsignedInt24();
addressPointer += 3;
} else {
- parentAddress = NO_PARENT_ADDRESS;
+ parentAddress = FormatSpec.NO_PARENT_ADDRESS;
}
final int characters[];
- if (0 != (flags & FLAG_HAS_MULTIPLE_CHARS)) {
+ if (0 != (flags & FormatSpec.FLAG_HAS_MULTIPLE_CHARS)) {
int index = 0;
int character = CharEncoding.readChar(buffer);
addressPointer += CharEncoding.getCharSize(character);
@@ -1311,33 +1118,33 @@ public class BinaryDictInputOutput {
characters = new int[] { character };
}
final int frequency;
- if (0 != (FLAG_IS_TERMINAL & flags)) {
+ if (0 != (FormatSpec.FLAG_IS_TERMINAL & flags)) {
++addressPointer;
frequency = buffer.readUnsignedByte();
} else {
frequency = CharGroup.NOT_A_TERMINAL;
}
int childrenAddress = addressPointer;
- switch (flags & MASK_GROUP_ADDRESS_TYPE) {
- case FLAG_GROUP_ADDRESS_TYPE_ONEBYTE:
+ switch (flags & FormatSpec.MASK_GROUP_ADDRESS_TYPE) {
+ case FormatSpec.FLAG_GROUP_ADDRESS_TYPE_ONEBYTE:
childrenAddress += buffer.readUnsignedByte();
addressPointer += 1;
break;
- case FLAG_GROUP_ADDRESS_TYPE_TWOBYTES:
+ case FormatSpec.FLAG_GROUP_ADDRESS_TYPE_TWOBYTES:
childrenAddress += buffer.readUnsignedShort();
addressPointer += 2;
break;
- case FLAG_GROUP_ADDRESS_TYPE_THREEBYTES:
+ case FormatSpec.FLAG_GROUP_ADDRESS_TYPE_THREEBYTES:
childrenAddress += buffer.readUnsignedInt24();
addressPointer += 3;
break;
- case FLAG_GROUP_ADDRESS_TYPE_NOADDRESS:
+ case FormatSpec.FLAG_GROUP_ADDRESS_TYPE_NOADDRESS:
default:
- childrenAddress = NO_CHILDREN_ADDRESS;
+ childrenAddress = FormatSpec.NO_CHILDREN_ADDRESS;
break;
}
ArrayList<WeightedString> shortcutTargets = null;
- if (0 != (flags & FLAG_HAS_SHORTCUT_TARGETS)) {
+ if (0 != (flags & FormatSpec.FLAG_HAS_SHORTCUT_TARGETS)) {
final int pointerBefore = buffer.position();
shortcutTargets = new ArrayList<WeightedString>();
buffer.readUnsignedShort(); // Skip the size
@@ -1345,29 +1152,30 @@ public class BinaryDictInputOutput {
final int targetFlags = buffer.readUnsignedByte();
final String word = CharEncoding.readString(buffer);
shortcutTargets.add(new WeightedString(word,
- targetFlags & FLAG_ATTRIBUTE_FREQUENCY));
- if (0 == (targetFlags & FLAG_ATTRIBUTE_HAS_NEXT)) break;
+ targetFlags & FormatSpec.FLAG_ATTRIBUTE_FREQUENCY));
+ if (0 == (targetFlags & FormatSpec.FLAG_ATTRIBUTE_HAS_NEXT)) break;
}
addressPointer += buffer.position() - pointerBefore;
}
ArrayList<PendingAttribute> bigrams = null;
- if (0 != (flags & FLAG_HAS_BIGRAMS)) {
+ if (0 != (flags & FormatSpec.FLAG_HAS_BIGRAMS)) {
bigrams = new ArrayList<PendingAttribute>();
while (true) {
final int bigramFlags = buffer.readUnsignedByte();
++addressPointer;
- final int sign = 0 == (bigramFlags & FLAG_ATTRIBUTE_OFFSET_NEGATIVE) ? 1 : -1;
+ final int sign = 0 == (bigramFlags & FormatSpec.FLAG_ATTRIBUTE_OFFSET_NEGATIVE)
+ ? 1 : -1;
int bigramAddress = addressPointer;
- switch (bigramFlags & MASK_ATTRIBUTE_ADDRESS_TYPE) {
- case FLAG_ATTRIBUTE_ADDRESS_TYPE_ONEBYTE:
+ switch (bigramFlags & FormatSpec.MASK_ATTRIBUTE_ADDRESS_TYPE) {
+ case FormatSpec.FLAG_ATTRIBUTE_ADDRESS_TYPE_ONEBYTE:
bigramAddress += sign * buffer.readUnsignedByte();
addressPointer += 1;
break;
- case FLAG_ATTRIBUTE_ADDRESS_TYPE_TWOBYTES:
+ case FormatSpec.FLAG_ATTRIBUTE_ADDRESS_TYPE_TWOBYTES:
bigramAddress += sign * buffer.readUnsignedShort();
addressPointer += 2;
break;
- case FLAG_ATTRIBUTE_ADDRESS_TYPE_THREEBYTES:
+ case FormatSpec.FLAG_ATTRIBUTE_ADDRESS_TYPE_THREEBYTES:
final int offset = (buffer.readUnsignedByte() << 16)
+ buffer.readUnsignedShort();
bigramAddress += sign * offset;
@@ -1376,9 +1184,9 @@ public class BinaryDictInputOutput {
default:
throw new RuntimeException("Has bigrams with no address");
}
- bigrams.add(new PendingAttribute(bigramFlags & FLAG_ATTRIBUTE_FREQUENCY,
+ bigrams.add(new PendingAttribute(bigramFlags & FormatSpec.FLAG_ATTRIBUTE_FREQUENCY,
bigramAddress));
- if (0 == (bigramFlags & FLAG_ATTRIBUTE_HAS_NEXT)) break;
+ if (0 == (bigramFlags & FormatSpec.FLAG_ATTRIBUTE_HAS_NEXT)) break;
}
}
return new CharGroupInfo(originalGroupAddress, addressPointer, flags, characters, frequency,
@@ -1390,10 +1198,10 @@ public class BinaryDictInputOutput {
*/
private static int readCharGroupCount(final FusionDictionaryBufferInterface buffer) {
final int msb = buffer.readUnsignedByte();
- if (MAX_CHARGROUPS_FOR_ONE_BYTE_CHARGROUP_COUNT >= msb) {
+ if (FormatSpec.MAX_CHARGROUPS_FOR_ONE_BYTE_CHARGROUP_COUNT >= msb) {
return msb;
} else {
- return ((MAX_CHARGROUPS_FOR_ONE_BYTE_CHARGROUP_COUNT & msb) << 8)
+ return ((FormatSpec.MAX_CHARGROUPS_FOR_ONE_BYTE_CHARGROUP_COUNT & msb) << 8)
+ buffer.readUnsignedByte();
}
}
@@ -1432,16 +1240,16 @@ public class BinaryDictInputOutput {
return result;
}
- private static int[] sGetWordBuffer = new int[MAX_WORD_LENGTH];
+ private static int[] sGetWordBuffer = new int[FormatSpec.MAX_WORD_LENGTH];
private static String getWordAtAddressWithParentAddress(
final FusionDictionaryBufferInterface buffer, final int headerSize, final int address,
final FormatOptions options) {
final StringBuilder builder = new StringBuilder();
int currentAddress = address;
- int index = MAX_WORD_LENGTH - 1;
+ int index = FormatSpec.MAX_WORD_LENGTH - 1;
// the length of the path from the root to the leaf is limited by MAX_WORD_LENGTH
- for (int count = 0; count < MAX_WORD_LENGTH; ++count) {
+ for (int count = 0; count < FormatSpec.MAX_WORD_LENGTH; ++count) {
buffer.position(currentAddress + headerSize);
final CharGroupInfo currentInfo = readCharGroup(buffer, currentAddress, options);
for (int i = 0; i < currentInfo.mCharacters.length; ++i) {
@@ -1449,11 +1257,11 @@ public class BinaryDictInputOutput {
currentInfo.mCharacters[currentInfo.mCharacters.length - i - 1];
}
- if (currentInfo.mParentAddress == NO_PARENT_ADDRESS) break;
+ if (currentInfo.mParentAddress == FormatSpec.NO_PARENT_ADDRESS) break;
currentAddress = currentInfo.mParentAddress + currentInfo.mOriginalAddress;
}
- return new String(sGetWordBuffer, index + 1, MAX_WORD_LENGTH - index - 1);
+ return new String(sGetWordBuffer, index + 1, FormatSpec.MAX_WORD_LENGTH - index - 1);
}
private static String getWordAtAddressWithoutParentAddress(
@@ -1544,13 +1352,13 @@ public class BinaryDictInputOutput {
}
nodeContents.add(
new CharGroup(info.mCharacters, shortcutTargets, bigrams, info.mFrequency,
- 0 != (info.mFlags & FLAG_IS_NOT_A_WORD),
- 0 != (info.mFlags & FLAG_IS_BLACKLISTED), children));
+ 0 != (info.mFlags & FormatSpec.FLAG_IS_NOT_A_WORD),
+ 0 != (info.mFlags & FormatSpec.FLAG_IS_BLACKLISTED), children));
} else {
nodeContents.add(
new CharGroup(info.mCharacters, shortcutTargets, bigrams, info.mFrequency,
- 0 != (info.mFlags & FLAG_IS_NOT_A_WORD),
- 0 != (info.mFlags & FLAG_IS_BLACKLISTED)));
+ 0 != (info.mFlags & FormatSpec.FLAG_IS_NOT_A_WORD),
+ 0 != (info.mFlags & FormatSpec.FLAG_IS_BLACKLISTED)));
}
groupOffset = info.mEndAddress;
}
@@ -1585,7 +1393,7 @@ public class BinaryDictInputOutput {
final Map<Integer, String> words, final Map<Integer, Integer> frequencies,
final Map<Integer, ArrayList<PendingAttribute>> bigrams,
final FormatOptions formatOptions) {
- int[] pushedChars = new int[MAX_WORD_LENGTH + 1];
+ int[] pushedChars = new int[FormatSpec.MAX_WORD_LENGTH + 1];
Stack<Position> stack = new Stack<Position>();
int index = 0;
@@ -1664,10 +1472,10 @@ public class BinaryDictInputOutput {
private static int getFormatVersion(final FusionDictionaryBufferInterface buffer)
throws IOException {
final int magic_v1 = buffer.readUnsignedShort();
- if (VERSION_1_MAGIC_NUMBER == magic_v1) return buffer.readUnsignedByte();
+ if (FormatSpec.VERSION_1_MAGIC_NUMBER == magic_v1) return buffer.readUnsignedByte();
final int magic_v2 = (magic_v1 << 16) + buffer.readUnsignedShort();
- if (VERSION_2_MAGIC_NUMBER == magic_v2) return buffer.readUnsignedShort();
- return NOT_A_VERSION_NUMBER;
+ if (FormatSpec.VERSION_2_MAGIC_NUMBER == magic_v2) return buffer.readUnsignedShort();
+ return FormatSpec.NOT_A_VERSION_NUMBER;
}
/**
@@ -1678,10 +1486,11 @@ public class BinaryDictInputOutput {
private static int checkFormatVersion(final FusionDictionaryBufferInterface buffer)
throws IOException, UnsupportedFormatException {
final int version = getFormatVersion(buffer);
- if (version < MINIMUM_SUPPORTED_VERSION || version > MAXIMUM_SUPPORTED_VERSION) {
+ if (version < FormatSpec.MINIMUM_SUPPORTED_VERSION
+ || version > FormatSpec.MAXIMUM_SUPPORTED_VERSION) {
throw new UnsupportedFormatException("This file has version " + version
+ ", but this implementation does not support versions above "
- + MAXIMUM_SUPPORTED_VERSION);
+ + FormatSpec.MAXIMUM_SUPPORTED_VERSION);
}
return version;
}
@@ -1699,7 +1508,7 @@ public class BinaryDictInputOutput {
final HashMap<String, String> attributes = new HashMap<String, String>();
final int headerSize;
- if (version < FIRST_VERSION_WITH_HEADER_SIZE) {
+ if (version < FormatSpec.FIRST_VERSION_WITH_HEADER_SIZE) {
headerSize = buffer.position();
} else {
headerSize = buffer.readInt();
@@ -1713,10 +1522,10 @@ public class BinaryDictInputOutput {
final FileHeader header = new FileHeader(headerSize,
new FusionDictionary.DictionaryOptions(attributes,
- 0 != (optionsFlags & GERMAN_UMLAUT_PROCESSING_FLAG),
- 0 != (optionsFlags & FRENCH_LIGATURE_PROCESSING_FLAG)),
+ 0 != (optionsFlags & FormatSpec.GERMAN_UMLAUT_PROCESSING_FLAG),
+ 0 != (optionsFlags & FormatSpec.FRENCH_LIGATURE_PROCESSING_FLAG)),
new FormatOptions(version,
- 0 != (optionsFlags & HAS_PARENT_ADDRESS)));
+ 0 != (optionsFlags & FormatSpec.HAS_PARENT_ADDRESS)));
return header;
}
@@ -1809,7 +1618,8 @@ public class BinaryDictInputOutput {
final ByteBuffer buffer = inStream.getChannel().map(
FileChannel.MapMode.READ_ONLY, 0, file.length());
final int version = getFormatVersion(new ByteBufferWrapper(buffer));
- return (version >= MINIMUM_SUPPORTED_VERSION && version <= MAXIMUM_SUPPORTED_VERSION);
+ return (version >= FormatSpec.MINIMUM_SUPPORTED_VERSION
+ && version <= FormatSpec.MAXIMUM_SUPPORTED_VERSION);
} catch (FileNotFoundException e) {
return false;
} catch (IOException e) {
@@ -1836,8 +1646,8 @@ public class BinaryDictInputOutput {
*/
public static int reconstructBigramFrequency(final int unigramFrequency,
final int bigramFrequency) {
- final float stepSize = (MAX_TERMINAL_FREQUENCY - unigramFrequency)
- / (1.5f + MAX_BIGRAM_FREQUENCY);
+ final float stepSize = (FormatSpec.MAX_TERMINAL_FREQUENCY - unigramFrequency)
+ / (1.5f + FormatSpec.MAX_BIGRAM_FREQUENCY);
final float resultFreqFloat = (float)unigramFrequency
+ stepSize * (bigramFrequency + 1.0f);
return (int)resultFreqFloat;
diff --git a/java/src/com/android/inputmethod/latin/makedict/FormatSpec.java b/java/src/com/android/inputmethod/latin/makedict/FormatSpec.java
new file mode 100644
index 000000000..1707ccc39
--- /dev/null
+++ b/java/src/com/android/inputmethod/latin/makedict/FormatSpec.java
@@ -0,0 +1,235 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package com.android.inputmethod.latin.makedict;
+
+import com.android.inputmethod.latin.Constants;
+import com.android.inputmethod.latin.makedict.FusionDictionary.DictionaryOptions;
+
+/**
+ * Dictionary File Format Specification.
+ */
+public final class FormatSpec {
+
+ /*
+ * Array of Node(FusionDictionary.Node) layout is as follows:
+ *
+ * g |
+ * r | the number of groups, 1 or 2 bytes.
+ * o | 1 byte = bbbbbbbb match
+ * u | case 1xxxxxxx => xxxxxxx << 8 + next byte
+ * p | otherwise => bbbbbbbb
+ * c |
+ * ount
+ *
+ * g |
+ * r | sequence of groups,
+ * o | the layout of each group is described below.
+ * u |
+ * ps
+ *
+ */
+
+ /* Node(CharGroup) layout is as follows:
+ * | addressType xx : mask with MASK_GROUP_ADDRESS_TYPE
+ * 2 bits, 00 = no children : FLAG_GROUP_ADDRESS_TYPE_NOADDRESS
+ * f | 01 = 1 byte : FLAG_GROUP_ADDRESS_TYPE_ONEBYTE
+ * l | 10 = 2 bytes : FLAG_GROUP_ADDRESS_TYPE_TWOBYTES
+ * a | 11 = 3 bytes : FLAG_GROUP_ADDRESS_TYPE_THREEBYTES
+ * g | has several chars ? 1 bit, 1 = yes, 0 = no : FLAG_HAS_MULTIPLE_CHARS
+ * s | has a terminal ? 1 bit, 1 = yes, 0 = no : FLAG_IS_TERMINAL
+ * | has shortcut targets ? 1 bit, 1 = yes, 0 = no : FLAG_HAS_SHORTCUT_TARGETS
+ * | has bigrams ? 1 bit, 1 = yes, 0 = no : FLAG_HAS_BIGRAMS
+ * | is not a word ? 1 bit, 1 = yes, 0 = no : FLAG_IS_NOT_A_WORD
+ * | is blacklisted ? 1 bit, 1 = yes, 0 = no : FLAG_IS_BLACKLISTED
+ *
+ * p |
+ * a | IF HAS_PARENT_ADDRESS (defined in the file header)
+ * r | parent address, 3byte
+ * e | the address must be negative, so the absolute value of the address is stored.
+ * n |
+ * taddress
+ *
+ * c | IF FLAG_HAS_MULTIPLE_CHARS
+ * h | char, char, char, char n * (1 or 3 bytes) : use CharGroupInfo for i/o helpers
+ * a | end 1 byte, = 0
+ * r | ELSE
+ * s | char 1 or 3 bytes
+ * | END
+ *
+ * f |
+ * r | IF FLAG_IS_TERMINAL
+ * e | frequency 1 byte
+ * q |
+ *
+ * c | IF 00 = FLAG_GROUP_ADDRESS_TYPE_NOADDRESS = addressType
+ * h | // nothing
+ * i | ELSIF 01 = FLAG_GROUP_ADDRESS_TYPE_ONEBYTE == addressType
+ * l | children address, 1 byte
+ * d | ELSIF 10 = FLAG_GROUP_ADDRESS_TYPE_TWOBYTES == addressType
+ * r | children address, 2 bytes
+ * e | ELSE // 11 = FLAG_GROUP_ADDRESS_TYPE_THREEBYTES = addressType
+ * n | children address, 3 bytes
+ * A | END
+ * d
+ * dress
+ *
+ * | IF FLAG_IS_TERMINAL && FLAG_HAS_SHORTCUT_TARGETS
+ * | shortcut string list
+ * | IF FLAG_IS_TERMINAL && FLAG_HAS_BIGRAMS
+ * | bigrams address list
+ *
+ * Char format is:
+ * 1 byte = bbbbbbbb match
+ * case 000xxxxx: xxxxx << 16 + next byte << 8 + next byte
+ * else: if 00011111 (= 0x1F) : this is the terminator. This is a relevant choice because
+ * unicode code points range from 0 to 0x10FFFF, so any 3-byte value starting with
+ * 00011111 would be outside unicode.
+ * else: iso-latin-1 code
+ * This allows for the whole unicode range to be encoded, including chars outside of
+ * the BMP. Also everything in the iso-latin-1 charset is only 1 byte, except control
+ * characters which should never happen anyway (and still work, but take 3 bytes).
+ *
+ * bigram address list is:
+ * <flags> = | hasNext = 1 bit, 1 = yes, 0 = no : FLAG_ATTRIBUTE_HAS_NEXT
+ * | addressSign = 1 bit, : FLAG_ATTRIBUTE_OFFSET_NEGATIVE
+ * | 1 = must take -address, 0 = must take +address
+ * | xx : mask with MASK_ATTRIBUTE_ADDRESS_TYPE
+ * | addressFormat = 2 bits, 00 = unused : FLAG_ATTRIBUTE_ADDRESS_TYPE_ONEBYTE
+ * | 01 = 1 byte : FLAG_ATTRIBUTE_ADDRESS_TYPE_ONEBYTE
+ * | 10 = 2 bytes : FLAG_ATTRIBUTE_ADDRESS_TYPE_TWOBYTES
+ * | 11 = 3 bytes : FLAG_ATTRIBUTE_ADDRESS_TYPE_THREEBYTES
+ * | 4 bits : frequency : mask with FLAG_ATTRIBUTE_FREQUENCY
+ * <address> | IF (01 == FLAG_ATTRIBUTE_ADDRESS_TYPE_ONEBYTE == addressFormat)
+ * | read 1 byte, add top 4 bits
+ * | ELSIF (10 == FLAG_ATTRIBUTE_ADDRESS_TYPE_TWOBYTES == addressFormat)
+ * | read 2 bytes, add top 4 bits
+ * | ELSE // 11 == FLAG_ATTRIBUTE_ADDRESS_TYPE_THREEBYTES == addressFormat
+ * | read 3 bytes, add top 4 bits
+ * | END
+ * | if (FLAG_ATTRIBUTE_OFFSET_NEGATIVE) then address = -address
+ * if (FLAG_ATTRIBUTE_HAS_NEXT) goto bigram_and_shortcut_address_list_is
+ *
+ * shortcut string list is:
+ * <byte size> = GROUP_SHORTCUT_LIST_SIZE_SIZE bytes, big-endian: size of the list, in bytes.
+ * <flags> = | hasNext = 1 bit, 1 = yes, 0 = no : FLAG_ATTRIBUTE_HAS_NEXT
+ * | reserved = 3 bits, must be 0
+ * | 4 bits : frequency : mask with FLAG_ATTRIBUTE_FREQUENCY
+ * <shortcut> = | string of characters at the char format described above, with the terminator
+ * | used to signal the end of the string.
+ * if (FLAG_ATTRIBUTE_HAS_NEXT goto flags
+ */
+
+ static final int VERSION_1_MAGIC_NUMBER = 0x78B1;
+ public static final int VERSION_2_MAGIC_NUMBER = 0x9BC13AFE;
+ static final int MINIMUM_SUPPORTED_VERSION = 1;
+ static final int MAXIMUM_SUPPORTED_VERSION = 3;
+ static final int NOT_A_VERSION_NUMBER = -1;
+ static final int FIRST_VERSION_WITH_HEADER_SIZE = 2;
+ static final int FIRST_VERSION_WITH_PARENT_ADDRESS = 3;
+
+ // These options need to be the same numeric values as the one in the native reading code.
+ static final int GERMAN_UMLAUT_PROCESSING_FLAG = 0x1;
+ static final int HAS_PARENT_ADDRESS = 0x2;
+ static final int FRENCH_LIGATURE_PROCESSING_FLAG = 0x4;
+ static final int CONTAINS_BIGRAMS_FLAG = 0x8;
+
+ // TODO: Make this value adaptative to content data, store it in the header, and
+ // use it in the reading code.
+ static final int MAX_WORD_LENGTH = Constants.Dictionary.MAX_WORD_LENGTH;
+
+ static final int PARENT_ADDRESS_SIZE = 3;
+
+ static final int MASK_GROUP_ADDRESS_TYPE = 0xC0;
+ static final int FLAG_GROUP_ADDRESS_TYPE_NOADDRESS = 0x00;
+ static final int FLAG_GROUP_ADDRESS_TYPE_ONEBYTE = 0x40;
+ static final int FLAG_GROUP_ADDRESS_TYPE_TWOBYTES = 0x80;
+ static final int FLAG_GROUP_ADDRESS_TYPE_THREEBYTES = 0xC0;
+
+ static final int FLAG_HAS_MULTIPLE_CHARS = 0x20;
+
+ static final int FLAG_IS_TERMINAL = 0x10;
+ static final int FLAG_HAS_SHORTCUT_TARGETS = 0x08;
+ static final int FLAG_HAS_BIGRAMS = 0x04;
+ static final int FLAG_IS_NOT_A_WORD = 0x02;
+ static final int FLAG_IS_BLACKLISTED = 0x01;
+
+ static final int FLAG_ATTRIBUTE_HAS_NEXT = 0x80;
+ static final int FLAG_ATTRIBUTE_OFFSET_NEGATIVE = 0x40;
+ static final int MASK_ATTRIBUTE_ADDRESS_TYPE = 0x30;
+ static final int FLAG_ATTRIBUTE_ADDRESS_TYPE_ONEBYTE = 0x10;
+ static final int FLAG_ATTRIBUTE_ADDRESS_TYPE_TWOBYTES = 0x20;
+ static final int FLAG_ATTRIBUTE_ADDRESS_TYPE_THREEBYTES = 0x30;
+ static final int FLAG_ATTRIBUTE_FREQUENCY = 0x0F;
+
+ static final int GROUP_CHARACTERS_TERMINATOR = 0x1F;
+
+ static final int GROUP_TERMINATOR_SIZE = 1;
+ static final int GROUP_FLAGS_SIZE = 1;
+ static final int GROUP_FREQUENCY_SIZE = 1;
+ static final int GROUP_MAX_ADDRESS_SIZE = 3;
+ static final int GROUP_ATTRIBUTE_FLAGS_SIZE = 1;
+ static final int GROUP_ATTRIBUTE_MAX_ADDRESS_SIZE = 3;
+ static final int GROUP_SHORTCUT_LIST_SIZE_SIZE = 2;
+
+ static final int NO_CHILDREN_ADDRESS = Integer.MIN_VALUE;
+ static final int NO_PARENT_ADDRESS = 0;
+ static final int INVALID_CHARACTER = -1;
+
+ static final int MAX_CHARGROUPS_FOR_ONE_BYTE_CHARGROUP_COUNT = 0x7F; // 127
+ static final int MAX_CHARGROUPS_IN_A_NODE = 0x7FFF; // 32767
+
+ static final int MAX_TERMINAL_FREQUENCY = 255;
+ static final int MAX_BIGRAM_FREQUENCY = 15;
+
+ /**
+ * Options about file format.
+ */
+ public static class FormatOptions {
+ public final int mVersion;
+ public final boolean mHasParentAddress;
+ public FormatOptions(final int version) {
+ this(version, false);
+ }
+ public FormatOptions(final int version, final boolean hasParentAddress) {
+ mVersion = version;
+ if (version < FormatSpec.FIRST_VERSION_WITH_PARENT_ADDRESS && hasParentAddress) {
+ throw new RuntimeException("Parent addresses are only supported with versions "
+ + FormatSpec.FIRST_VERSION_WITH_PARENT_ADDRESS + " and ulterior.");
+ }
+ mHasParentAddress = hasParentAddress;
+ }
+ }
+
+ /**
+ * Class representing file header.
+ */
+ static final class FileHeader {
+ public final int mHeaderSize;
+ public final DictionaryOptions mDictionaryOptions;
+ public final FormatOptions mFormatOptions;
+ public FileHeader(final int headerSize, final DictionaryOptions dictionaryOptions,
+ final FormatOptions formatOptions) {
+ mHeaderSize = headerSize;
+ mDictionaryOptions = dictionaryOptions;
+ mFormatOptions = formatOptions;
+ }
+ }
+
+ private FormatSpec() {
+ // This utility class is not publicly instantiable.
+ }
+}