diff options
author | 2013-01-31 16:59:10 +0000 | |
---|---|---|
committer | 2013-01-31 16:59:11 +0000 | |
commit | 5ea4365f077f59341430e00ed34a5d74b7877931 (patch) | |
tree | a18cbe772ae91a84351f13f81244c2d9ce5161f2 /java/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java | |
parent | 4920d370f2a9f14bcc14212738590c22bd3752d0 (diff) | |
parent | af4a7e8c4b2a41e9be48965133ab489cc9484764 (diff) | |
download | latinime-5ea4365f077f59341430e00ed34a5d74b7877931.tar.gz latinime-5ea4365f077f59341430e00ed34a5d74b7877931.tar.xz latinime-5ea4365f077f59341430e00ed34a5d74b7877931.zip |
Merge "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; + } + } } |