diff options
author | 2013-10-18 01:01:28 -0700 | |
---|---|---|
committer | 2013-10-18 01:01:28 -0700 | |
commit | 1dbc930c0f8d4bf9bd6e4b46c7499261ef27f6b0 (patch) | |
tree | c5d0a12b832780270afae256199115fc77893a8f /java/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java | |
parent | f2d6992f026f95af9b7029242e7a65abad1d7d96 (diff) | |
parent | 7e7fe6057a61bd5d35529f19a2537e37f612ad31 (diff) | |
download | latinime-1dbc930c0f8d4bf9bd6e4b46c7499261ef27f6b0.tar.gz latinime-1dbc930c0f8d4bf9bd6e4b46c7499261ef27f6b0.tar.xz latinime-1dbc930c0f8d4bf9bd6e4b46c7499261ef27f6b0.zip |
am 7e7fe605: Merge "(1/2) Implement insertWord in Ver4DictUpdater."
* commit '7e7fe6057a61bd5d35529f19a2537e37f612ad31':
(1/2) Implement insertWord in Ver4DictUpdater.
Diffstat (limited to 'java/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/java/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java b/java/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java index 9a28629b1..8d14e4d60 100644 --- a/java/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java +++ b/java/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java @@ -245,8 +245,7 @@ public final class BinaryDictIOUtils { /** * @return the size written, in bytes. Always 3 bytes. */ - static int writeSInt24ToBuffer(final DictBuffer dictBuffer, - final int value) { + static int writeSInt24ToBuffer(final DictBuffer dictBuffer, final int value) { final int absValue = Math.abs(value); dictBuffer.put((byte)(((value < 0 ? 0x80 : 0) | (absValue >> 16)) & 0xFF)); dictBuffer.put((byte)((absValue >> 8) & 0xFF)); @@ -416,6 +415,25 @@ public final class BinaryDictIOUtils { } /** + * Writes a PtNodeCount to the stream. + * + * @param destination the stream to write. + * @param ptNodeCount the count. + * @return the size written in bytes. + */ + static int writePtNodeCount(final OutputStream destination, final int ptNodeCount) + throws IOException { + final int countSize = BinaryDictIOUtils.getPtNodeCountSize(ptNodeCount); + // the count must fit on one byte or two bytes. + // Please see comments in FormatSpec. + if (countSize != 1 && countSize != 2) { + throw new RuntimeException("Strange size from getPtNodeCountSize : " + countSize); + } + BinaryDictEncoderUtils.writeUIntToStream(destination, ptNodeCount, countSize); + return countSize; + } + + /** * Write a node array to the stream. * * @param destination the stream to write. @@ -425,18 +443,7 @@ public final class BinaryDictIOUtils { */ static int writeNodes(final OutputStream destination, final PtNodeInfo[] infos) throws IOException { - int size = getPtNodeCountSize(infos.length); - switch (getPtNodeCountSize(infos.length)) { - case 1: - destination.write((byte)infos.length); - break; - case 2: - destination.write((byte)(infos.length >> 8)); - destination.write((byte)(infos.length & 0xFF)); - break; - default: - throw new RuntimeException("Invalid node count size."); - } + int size = writePtNodeCount(destination, infos.length); for (final PtNodeInfo info : infos) size += writePtNode(destination, info); writeSInt24ToStream(destination, FormatSpec.NO_FORWARD_LINK_ADDRESS); return size + FormatSpec.FORWARD_LINK_ADDRESS_SIZE; |