Loading java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java +3 −2 Original line number Diff line number Diff line Loading @@ -21,9 +21,10 @@ import android.content.SharedPreferences; import android.content.res.AssetFileDescriptor; import android.util.Log; import com.android.inputmethod.latin.makedict.DictDecoder; import com.android.inputmethod.latin.makedict.FormatSpec; import com.android.inputmethod.latin.makedict.FormatSpec.FileHeader; import com.android.inputmethod.latin.makedict.UnsupportedFormatException; import com.android.inputmethod.latin.makedict.Ver3DictDecoder; import com.android.inputmethod.latin.utils.CollectionUtils; import com.android.inputmethod.latin.utils.DictionaryInfoUtils; import com.android.inputmethod.latin.utils.LocaleUtils; Loading Loading @@ -228,7 +229,7 @@ final public class BinaryDictionaryGetter { private static boolean hackCanUseDictionaryFile(final Locale locale, final File f) { try { // Read the version of the file final Ver3DictDecoder dictDecoder = new Ver3DictDecoder(f); final DictDecoder dictDecoder = FormatSpec.getDictDecoder(f); final FileHeader header = dictDecoder.readHeader(); final String version = header.mDictionaryOptions.mAttributes.get(VERSION_KEY); Loading java/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java +3 −3 Original line number Diff line number Diff line Loading @@ -148,7 +148,7 @@ public final class BinaryDictIOUtils { * @throws IOException if the file can't be read. * @throws UnsupportedFormatException if the format of the file is not recognized. */ /* package */ static void readUnigramsAndBigramsBinary(final Ver3DictDecoder dictDecoder, /* package */ static void readUnigramsAndBigramsBinary(final DictDecoder dictDecoder, final Map<Integer, String> words, final Map<Integer, Integer> frequencies, final Map<Integer, ArrayList<PendingAttribute>> bigrams) throws IOException, UnsupportedFormatException { Loading @@ -169,7 +169,7 @@ public final class BinaryDictIOUtils { * @throws UnsupportedFormatException if the format of the file is not recognized. */ @UsedForTesting /* package */ static int getTerminalPosition(final Ver3DictDecoder dictDecoder, /* package */ static int getTerminalPosition(final DictDecoder dictDecoder, final String word) throws IOException, UnsupportedFormatException { if (word == null) return FormatSpec.NOT_VALID_WORD; dictDecoder.setPosition(0); Loading Loading @@ -519,7 +519,7 @@ public final class BinaryDictIOUtils { final File file, final long offset, final long length) throws FileNotFoundException, IOException, UnsupportedFormatException { final byte[] buffer = new byte[HEADER_READING_BUFFER_SIZE]; final Ver3DictDecoder dictDecoder = new Ver3DictDecoder(file, final DictDecoder dictDecoder = FormatSpec.getDictDecoder(file, new DictDecoder.DictionaryBufferFactory() { @Override public DictBuffer getDictionaryBuffer(File file) Loading java/src/com/android/inputmethod/latin/makedict/DictDecoder.java +8 −0 Original line number Diff line number Diff line Loading @@ -118,6 +118,14 @@ public interface DictDecoder { public boolean readForwardLinkAndAdvancePosition(); public boolean hasNextPtNodeArray(); /** * Opens the dictionary file and makes DictBuffer. */ @UsedForTesting public void openDictBuffer() throws FileNotFoundException, IOException; @UsedForTesting public boolean isOpenedDictBuffer(); // Flags for DictionaryBufferFactory. public static final int USE_READONLY_BYTEBUFFER = 0x01000000; public static final int USE_BYTEARRAY = 0x02000000; Loading java/src/com/android/inputmethod/latin/makedict/FormatSpec.java +25 −0 Original line number Diff line number Diff line Loading @@ -18,8 +18,11 @@ package com.android.inputmethod.latin.makedict; import com.android.inputmethod.annotations.UsedForTesting; import com.android.inputmethod.latin.Constants; import com.android.inputmethod.latin.makedict.DictDecoder.DictionaryBufferFactory; import com.android.inputmethod.latin.makedict.FusionDictionary.DictionaryOptions; import java.io.File; /** * Dictionary File Format Specification. */ Loading Loading @@ -341,6 +344,28 @@ public final class FormatSpec { } } /** * Returns new dictionary decoder. * * @param dictFile the dictionary file. * @param bufferType the flag indicating buffer type which is used by the dictionary decoder. * @return new dictionary decoder if the dictionary file exists, otherwise null. */ public static DictDecoder getDictDecoder(final File dictFile, final int bufferType) { if (!dictFile.isFile()) return null; return new Ver3DictDecoder(dictFile, bufferType); } public static DictDecoder getDictDecoder(final File dictFile, final DictionaryBufferFactory factory) { if (!dictFile.isFile()) return null; return new Ver3DictDecoder(dictFile, factory); } public static DictDecoder getDictDecoder(final File dictFile) { return getDictDecoder(dictFile, DictDecoder.USE_READONLY_BYTEBUFFER); } private FormatSpec() { // This utility class is not publicly instantiable. } Loading java/src/com/android/inputmethod/latin/makedict/Ver3DictDecoder.java +8 −6 Original line number Diff line number Diff line Loading @@ -173,11 +173,7 @@ public class Ver3DictDecoder implements DictDecoder { private final DictionaryBufferFactory mBufferFactory; private DictBuffer mDictBuffer; public Ver3DictDecoder(final File file) { this(file, USE_READONLY_BYTEBUFFER); } public Ver3DictDecoder(final File file, final int factoryFlag) { /* package */ Ver3DictDecoder(final File file, final int factoryFlag) { mDictionaryBinaryFile = file; mDictBuffer = null; Loading @@ -192,15 +188,21 @@ public class Ver3DictDecoder implements DictDecoder { } } public Ver3DictDecoder(final File file, final DictionaryBufferFactory factory) { /* package */ Ver3DictDecoder(final File file, final DictionaryBufferFactory factory) { mDictionaryBinaryFile = file; mBufferFactory = factory; } @Override public void openDictBuffer() throws FileNotFoundException, IOException { mDictBuffer = mBufferFactory.getDictionaryBuffer(mDictionaryBinaryFile); } @Override public boolean isOpenedDictBuffer() { return mDictBuffer != null; } /* package */ DictBuffer getDictBuffer() { return mDictBuffer; } Loading Loading
java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java +3 −2 Original line number Diff line number Diff line Loading @@ -21,9 +21,10 @@ import android.content.SharedPreferences; import android.content.res.AssetFileDescriptor; import android.util.Log; import com.android.inputmethod.latin.makedict.DictDecoder; import com.android.inputmethod.latin.makedict.FormatSpec; import com.android.inputmethod.latin.makedict.FormatSpec.FileHeader; import com.android.inputmethod.latin.makedict.UnsupportedFormatException; import com.android.inputmethod.latin.makedict.Ver3DictDecoder; import com.android.inputmethod.latin.utils.CollectionUtils; import com.android.inputmethod.latin.utils.DictionaryInfoUtils; import com.android.inputmethod.latin.utils.LocaleUtils; Loading Loading @@ -228,7 +229,7 @@ final public class BinaryDictionaryGetter { private static boolean hackCanUseDictionaryFile(final Locale locale, final File f) { try { // Read the version of the file final Ver3DictDecoder dictDecoder = new Ver3DictDecoder(f); final DictDecoder dictDecoder = FormatSpec.getDictDecoder(f); final FileHeader header = dictDecoder.readHeader(); final String version = header.mDictionaryOptions.mAttributes.get(VERSION_KEY); Loading
java/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java +3 −3 Original line number Diff line number Diff line Loading @@ -148,7 +148,7 @@ public final class BinaryDictIOUtils { * @throws IOException if the file can't be read. * @throws UnsupportedFormatException if the format of the file is not recognized. */ /* package */ static void readUnigramsAndBigramsBinary(final Ver3DictDecoder dictDecoder, /* package */ static void readUnigramsAndBigramsBinary(final DictDecoder dictDecoder, final Map<Integer, String> words, final Map<Integer, Integer> frequencies, final Map<Integer, ArrayList<PendingAttribute>> bigrams) throws IOException, UnsupportedFormatException { Loading @@ -169,7 +169,7 @@ public final class BinaryDictIOUtils { * @throws UnsupportedFormatException if the format of the file is not recognized. */ @UsedForTesting /* package */ static int getTerminalPosition(final Ver3DictDecoder dictDecoder, /* package */ static int getTerminalPosition(final DictDecoder dictDecoder, final String word) throws IOException, UnsupportedFormatException { if (word == null) return FormatSpec.NOT_VALID_WORD; dictDecoder.setPosition(0); Loading Loading @@ -519,7 +519,7 @@ public final class BinaryDictIOUtils { final File file, final long offset, final long length) throws FileNotFoundException, IOException, UnsupportedFormatException { final byte[] buffer = new byte[HEADER_READING_BUFFER_SIZE]; final Ver3DictDecoder dictDecoder = new Ver3DictDecoder(file, final DictDecoder dictDecoder = FormatSpec.getDictDecoder(file, new DictDecoder.DictionaryBufferFactory() { @Override public DictBuffer getDictionaryBuffer(File file) Loading
java/src/com/android/inputmethod/latin/makedict/DictDecoder.java +8 −0 Original line number Diff line number Diff line Loading @@ -118,6 +118,14 @@ public interface DictDecoder { public boolean readForwardLinkAndAdvancePosition(); public boolean hasNextPtNodeArray(); /** * Opens the dictionary file and makes DictBuffer. */ @UsedForTesting public void openDictBuffer() throws FileNotFoundException, IOException; @UsedForTesting public boolean isOpenedDictBuffer(); // Flags for DictionaryBufferFactory. public static final int USE_READONLY_BYTEBUFFER = 0x01000000; public static final int USE_BYTEARRAY = 0x02000000; Loading
java/src/com/android/inputmethod/latin/makedict/FormatSpec.java +25 −0 Original line number Diff line number Diff line Loading @@ -18,8 +18,11 @@ package com.android.inputmethod.latin.makedict; import com.android.inputmethod.annotations.UsedForTesting; import com.android.inputmethod.latin.Constants; import com.android.inputmethod.latin.makedict.DictDecoder.DictionaryBufferFactory; import com.android.inputmethod.latin.makedict.FusionDictionary.DictionaryOptions; import java.io.File; /** * Dictionary File Format Specification. */ Loading Loading @@ -341,6 +344,28 @@ public final class FormatSpec { } } /** * Returns new dictionary decoder. * * @param dictFile the dictionary file. * @param bufferType the flag indicating buffer type which is used by the dictionary decoder. * @return new dictionary decoder if the dictionary file exists, otherwise null. */ public static DictDecoder getDictDecoder(final File dictFile, final int bufferType) { if (!dictFile.isFile()) return null; return new Ver3DictDecoder(dictFile, bufferType); } public static DictDecoder getDictDecoder(final File dictFile, final DictionaryBufferFactory factory) { if (!dictFile.isFile()) return null; return new Ver3DictDecoder(dictFile, factory); } public static DictDecoder getDictDecoder(final File dictFile) { return getDictDecoder(dictFile, DictDecoder.USE_READONLY_BYTEBUFFER); } private FormatSpec() { // This utility class is not publicly instantiable. } Loading
java/src/com/android/inputmethod/latin/makedict/Ver3DictDecoder.java +8 −6 Original line number Diff line number Diff line Loading @@ -173,11 +173,7 @@ public class Ver3DictDecoder implements DictDecoder { private final DictionaryBufferFactory mBufferFactory; private DictBuffer mDictBuffer; public Ver3DictDecoder(final File file) { this(file, USE_READONLY_BYTEBUFFER); } public Ver3DictDecoder(final File file, final int factoryFlag) { /* package */ Ver3DictDecoder(final File file, final int factoryFlag) { mDictionaryBinaryFile = file; mDictBuffer = null; Loading @@ -192,15 +188,21 @@ public class Ver3DictDecoder implements DictDecoder { } } public Ver3DictDecoder(final File file, final DictionaryBufferFactory factory) { /* package */ Ver3DictDecoder(final File file, final DictionaryBufferFactory factory) { mDictionaryBinaryFile = file; mBufferFactory = factory; } @Override public void openDictBuffer() throws FileNotFoundException, IOException { mDictBuffer = mBufferFactory.getDictionaryBuffer(mDictionaryBinaryFile); } @Override public boolean isOpenedDictBuffer() { return mDictBuffer != null; } /* package */ DictBuffer getDictBuffer() { return mDictBuffer; } Loading