diff options
author | 2014-03-05 23:34:14 -0800 | |
---|---|---|
committer | 2014-03-05 23:34:14 -0800 | |
commit | 2cb31a0f23863e59ebffbe590712016fd6f88ec9 (patch) | |
tree | 0133f8580b2e85be2410b0f71759c2dd8521fe0c /java/src/com/android/inputmethod/latin/makedict | |
parent | ea3c70ebe21e6dacab9ec99c44d85d6d40b8a3d7 (diff) | |
parent | d93eb680c463f6258f8b9e31bb379545b8679357 (diff) | |
download | latinime-2cb31a0f23863e59ebffbe590712016fd6f88ec9.tar.gz latinime-2cb31a0f23863e59ebffbe590712016fd6f88ec9.tar.xz latinime-2cb31a0f23863e59ebffbe590712016fd6f88ec9.zip |
am d93eb680: Merge "Use BinaryDictionaryUtils to read dictionary header."
* commit 'd93eb680c463f6258f8b9e31bb379545b8679357':
Use BinaryDictionaryUtils to read dictionary header.
Diffstat (limited to 'java/src/com/android/inputmethod/latin/makedict')
3 files changed, 3 insertions, 48 deletions
diff --git a/java/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java b/java/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java index 90e7400fb..caf3cf354 100644 --- a/java/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java +++ b/java/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java @@ -222,54 +222,6 @@ public final class BinaryDictIOUtils { return countSize; } - private static final int HEADER_READING_BUFFER_SIZE = 16384; - /** - * Convenience method to read the header of a binary file. - * - * This is quite resource intensive - don't call when performance is critical. - * - * @param file The file to read. - * @param offset The offset in the file where to start reading the data. - * @param length The length of the data file. - * @return the header of the specified dictionary file. - */ - private static DictionaryHeader getDictionaryFileHeader( - final File file, final long offset, final long length) - throws FileNotFoundException, IOException, UnsupportedFormatException { - final byte[] buffer = new byte[HEADER_READING_BUFFER_SIZE]; - final DictDecoder dictDecoder = FormatSpec.getDictDecoder(file, offset, length, - new DictDecoder.DictionaryBufferFactory() { - @Override - public DictBuffer getDictionaryBuffer(File file) - throws FileNotFoundException, IOException { - final FileInputStream inStream = new FileInputStream(file); - try { - inStream.skip(offset); - inStream.read(buffer); - return new ByteArrayDictBuffer(buffer); - } finally { - inStream.close(); - } - } - }); - if (dictDecoder == null) { - return null; - } - return dictDecoder.readHeader(); - } - - public static DictionaryHeader getDictionaryFileHeaderOrNull(final File file, final long offset, - final long length) { - try { - final DictionaryHeader header = getDictionaryFileHeader(file, offset, length); - return header; - } catch (UnsupportedFormatException e) { - return null; - } catch (IOException e) { - return null; - } - } - /** * Helper method to hide the actual value of the no children address. */ diff --git a/java/src/com/android/inputmethod/latin/makedict/FormatSpec.java b/java/src/com/android/inputmethod/latin/makedict/FormatSpec.java index 9abecbfec..484bb4b23 100644 --- a/java/src/com/android/inputmethod/latin/makedict/FormatSpec.java +++ b/java/src/com/android/inputmethod/latin/makedict/FormatSpec.java @@ -341,6 +341,7 @@ public final class FormatSpec { return null; } + @UsedForTesting public static DictDecoder getDictDecoder(final File dictFile, final long offset, final long length, final DictionaryBufferFactory factory) { if (dictFile.isDirectory()) { @@ -351,6 +352,7 @@ public final class FormatSpec { return null; } + @UsedForTesting public static DictDecoder getDictDecoder(final File dictFile, final long offset, final long length) { return getDictDecoder(dictFile, offset, length, DictDecoder.USE_READONLY_BYTEBUFFER); diff --git a/java/src/com/android/inputmethod/latin/makedict/Ver2DictDecoder.java b/java/src/com/android/inputmethod/latin/makedict/Ver2DictDecoder.java index ae1e443c5..ab24fbc84 100644 --- a/java/src/com/android/inputmethod/latin/makedict/Ver2DictDecoder.java +++ b/java/src/com/android/inputmethod/latin/makedict/Ver2DictDecoder.java @@ -123,6 +123,7 @@ public class Ver2DictDecoder extends AbstractDictDecoder { private final DictionaryBufferFactory mBufferFactory; protected DictBuffer mDictBuffer; + @UsedForTesting /* package */ Ver2DictDecoder(final File file, final long offset, final long length, final int factoryFlag) { mDictionaryBinaryFile = file; |