diff options
author | 2013-12-11 03:37:05 +0000 | |
---|---|---|
committer | 2013-12-11 03:37:05 +0000 | |
commit | a8ffdf0288288cb7a0386cc21e95913d6092e80a (patch) | |
tree | 772c50001fd808637090b8fd54b203dffe56bc17 /java/src/com/android/inputmethod/latin/makedict/Ver4DictDecoder.java | |
parent | 499371a5efdd5e3b76d12370fcd63fb7963a2488 (diff) | |
parent | 3839defc90b8328592256d92caa90102c34a5937 (diff) | |
download | latinime-a8ffdf0288288cb7a0386cc21e95913d6092e80a.tar.gz latinime-a8ffdf0288288cb7a0386cc21e95913d6092e80a.tar.xz latinime-a8ffdf0288288cb7a0386cc21e95913d6092e80a.zip |
Merge "Split the header into a separate file."
Diffstat (limited to 'java/src/com/android/inputmethod/latin/makedict/Ver4DictDecoder.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/makedict/Ver4DictDecoder.java | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/java/src/com/android/inputmethod/latin/makedict/Ver4DictDecoder.java b/java/src/com/android/inputmethod/latin/makedict/Ver4DictDecoder.java index 2cbec7cec..07522b54b 100644 --- a/java/src/com/android/inputmethod/latin/makedict/Ver4DictDecoder.java +++ b/java/src/com/android/inputmethod/latin/makedict/Ver4DictDecoder.java @@ -45,10 +45,12 @@ public class Ver4DictDecoder extends AbstractDictDecoder { protected static final int FILETYPE_TERMINAL_ADDRESS_TABLE = 3; protected static final int FILETYPE_BIGRAM_FREQ = 4; protected static final int FILETYPE_SHORTCUT = 5; + protected static final int FILETYPE_HEADER = 6; protected final File mDictDirectory; protected final DictionaryBufferFactory mBufferFactory; protected DictBuffer mDictBuffer; + protected DictBuffer mHeaderBuffer; protected DictBuffer mFrequencyBuffer; protected DictBuffer mTerminalAddressTableBuffer; private BigramContentReader mBigramReader; @@ -83,7 +85,7 @@ public class Ver4DictDecoder extends AbstractDictDecoder { @UsedForTesting /* package */ Ver4DictDecoder(final File dictDirectory, final int factoryFlag) { mDictDirectory = dictDirectory; - mDictBuffer = mFrequencyBuffer = null; + mDictBuffer = mHeaderBuffer = mFrequencyBuffer = null; if ((factoryFlag & MASK_DICTBUFFER) == USE_READONLY_BYTEBUFFER) { mBufferFactory = new DictionaryBufferFromReadOnlyByteBufferFactory(); @@ -100,13 +102,16 @@ public class Ver4DictDecoder extends AbstractDictDecoder { /* package */ Ver4DictDecoder(final File dictDirectory, final DictionaryBufferFactory factory) { mDictDirectory = dictDirectory; mBufferFactory = factory; - mDictBuffer = mFrequencyBuffer = null; + mDictBuffer = mHeaderBuffer = mFrequencyBuffer = null; } protected File getFile(final int fileType) throws UnsupportedFormatException { if (fileType == FILETYPE_TRIE) { return new File(mDictDirectory, mDictDirectory.getName() + FormatSpec.TRIE_FILE_EXTENSION); + } else if (fileType == FILETYPE_HEADER) { + return new File(mDictDirectory, + mDictDirectory.getName() + FormatSpec.HEADER_FILE_EXTENSION); } else if (fileType == FILETYPE_FREQUENCY) { return new File(mDictDirectory, mDictDirectory.getName() + FormatSpec.FREQ_FILE_EXTENSION); @@ -132,6 +137,7 @@ public class Ver4DictDecoder extends AbstractDictDecoder { if (!mDictDirectory.isDirectory()) { throw new UnsupportedFormatException("Format 4 dictionary needs a directory"); } + mHeaderBuffer = mBufferFactory.getDictionaryBuffer(getFile(FILETYPE_HEADER)); mDictBuffer = mBufferFactory.getDictionaryBuffer(getFile(FILETYPE_TRIE)); mFrequencyBuffer = mBufferFactory.getDictionaryBuffer(getFile(FILETYPE_FREQUENCY)); mTerminalAddressTableBuffer = mBufferFactory.getDictionaryBuffer( @@ -150,16 +156,22 @@ public class Ver4DictDecoder extends AbstractDictDecoder { } @UsedForTesting + /* package */ DictBuffer getHeaderBuffer() { + return mHeaderBuffer; + } + + @UsedForTesting /* package */ DictBuffer getDictBuffer() { return mDictBuffer; } @Override public FileHeader readHeader() throws IOException, UnsupportedFormatException { - if (mDictBuffer == null) { + if (mHeaderBuffer == null) { openDictBuffer(); } - final FileHeader header = super.readHeader(mDictBuffer); + mHeaderBuffer.position(0); + final FileHeader header = super.readHeader(mHeaderBuffer); final int version = header.mFormatOptions.mVersion; if (version != FormatSpec.VERSION4) { throw new UnsupportedFormatException("File header has a wrong version : " + version); |