diff options
author | 2013-08-12 14:47:20 +0900 | |
---|---|---|
committer | 2013-08-13 19:55:05 +0900 | |
commit | 3feacba1eb43fb906f50581df19ff2e468642ca8 (patch) | |
tree | 269cd27201fbfad661734ad12367d5f762881f11 /java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java | |
parent | 7242bf1a159b909db8a7c74e786e2391a4361d85 (diff) | |
download | latinime-3feacba1eb43fb906f50581df19ff2e468642ca8.tar.gz latinime-3feacba1eb43fb906f50581df19ff2e468642ca8.tar.xz latinime-3feacba1eb43fb906f50581df19ff2e468642ca8.zip |
Add BinaryDictReader.
Bug: 9618601
Change-Id: Ief07fa0c3c4f7f5999a3fafcef4e47b6b6fd8143
Diffstat (limited to 'java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java | 20 |
1 files changed, 14 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 e0874bbd5..504349a0b 100644 --- a/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java +++ b/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java @@ -66,6 +66,7 @@ public final class BinaryDictInputOutput { public void position(int newPosition); public void put(final byte b); public int limit(); + @UsedForTesting public int capacity(); } @@ -1722,23 +1723,30 @@ public final class BinaryDictInputOutput { * FusionDictionary structure. The optional dict argument is an existing dictionary to * which words from the buffer should be added. If it is null, a new dictionary is created. * - * @param buffer the buffer to read. + * @param reader the reader. * @param dict an optional dictionary to add words to, or null. * @return the created (or merged) dictionary. */ @UsedForTesting - public static FusionDictionary readDictionaryBinary( - final FusionDictionaryBufferInterface buffer, final FusionDictionary dict) - throws IOException, UnsupportedFormatException { + public static FusionDictionary readDictionaryBinary(final BinaryDictReader reader, + final FusionDictionary dict) throws FileNotFoundException, IOException, + UnsupportedFormatException { // clear cache wordCache.clear(); + // if the buffer has not been opened, open the buffer with bytebuffer. + if (reader.getBuffer() == null) reader.openBuffer( + new BinaryDictReader.FusionDictionaryBufferFromByteBufferFactory()); + if (reader.getBuffer() == null) { + MakedictLog.e("Cannot open the buffer"); + } + // Read header - final FileHeader header = readHeader(buffer); + final FileHeader header = readHeader(reader.getBuffer()); Map<Integer, Node> reverseNodeMapping = new TreeMap<Integer, Node>(); Map<Integer, CharGroup> reverseGroupMapping = new TreeMap<Integer, CharGroup>(); - final Node root = readNode(buffer, header.mHeaderSize, reverseNodeMapping, + final Node root = readNode(reader.getBuffer(), header.mHeaderSize, reverseNodeMapping, reverseGroupMapping, header.mFormatOptions); FusionDictionary newDict = new FusionDictionary(root, header.mDictionaryOptions); |