diff options
author | 2013-01-31 09:01:19 -0800 | |
---|---|---|
committer | 2013-01-31 09:01:19 -0800 | |
commit | 0d42b8cb8a21afef40933682e6bae7bf6e3eef42 (patch) | |
tree | 0ccf69b77a20e7280cb4f264cf7b8bc57e8f103e /java/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java | |
parent | ca2b14c5e334d8b0c67fc8c88b2296f779e74595 (diff) | |
parent | 5ea4365f077f59341430e00ed34a5d74b7877931 (diff) | |
download | latinime-0d42b8cb8a21afef40933682e6bae7bf6e3eef42.tar.gz latinime-0d42b8cb8a21afef40933682e6bae7bf6e3eef42.tar.xz latinime-0d42b8cb8a21afef40933682e6bae7bf6e3eef42.zip |
am 5ea4365f: Merge "Create methods in LatinIME to make the current dict lists"
# Via Android (Google) Code Review (1) and Jean Chalard (1)
* commit '5ea4365f077f59341430e00ed34a5d74b7877931':
Create methods in LatinIME to make the current dict lists
Diffstat (limited to 'java/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/java/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java b/java/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java index 9e1f7517d..c87a9254d 100644 --- a/java/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java +++ b/java/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java @@ -988,20 +988,35 @@ public final class BinaryDictIOUtils { * 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. */ private static final int HEADER_READING_BUFFER_SIZE = 16384; - public static FileHeader getDictionaryFileHeader(final File file) - throws FileNotFoundException, IOException, UnsupportedFormatException { + public static FileHeader getDictionaryFileHeader( + final File file, final long offset, final long length) + throws FileNotFoundException, IOException, UnsupportedFormatException { final byte[] buffer = new byte[HEADER_READING_BUFFER_SIZE]; final FileInputStream inStream = new FileInputStream(file); try { inStream.read(buffer); final BinaryDictInputOutput.ByteBufferWrapper wrapper = new BinaryDictInputOutput.ByteBufferWrapper(inStream.getChannel().map( - FileChannel.MapMode.READ_ONLY, 0, file.length())); + FileChannel.MapMode.READ_ONLY, offset, length)); return BinaryDictInputOutput.readHeader(wrapper); } finally { inStream.close(); } } + + public static FileHeader getDictionaryFileHeaderOrNull(final File file, final long offset, + final long length) { + try { + final FileHeader header = getDictionaryFileHeader(file, offset, length); + return header; + } catch (UnsupportedFormatException e) { + return null; + } catch (IOException e) { + return null; + } + } } |