aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java
diff options
context:
space:
mode:
authorJean Chalard <jchalard@google.com>2011-04-15 15:19:25 +0900
committerJean Chalard <jchalard@google.com>2011-04-15 17:38:24 +0900
commit4e3bd58b862afadd0325746b5c7ca9145b771762 (patch)
tree693f5f8e5838b503b354f541c4acf69e8569570e /java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java
parent72a82d7ee848a0a380350197bee0b8500600fa33 (diff)
downloadlatinime-4e3bd58b862afadd0325746b5c7ca9145b771762.tar.gz
latinime-4e3bd58b862afadd0325746b5c7ca9145b771762.tar.xz
latinime-4e3bd58b862afadd0325746b5c7ca9145b771762.zip
Allow use of assets for data in the dictionary content provider.
This update is necessary to allow dictionary content providers to use assets, which are part of their apk, as data to pass to the keyboard. Using plain file descriptors doesn't allow for sections of files to be correctly used. Change-Id: Ia94c26d6387bce61c73d38f5c2821f20e50e54d4
Diffstat (limited to 'java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java')
-rw-r--r--java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java9
1 files changed, 6 insertions, 3 deletions
diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java b/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java
index d0464dd94..a78ff7e84 100644
--- a/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java
+++ b/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java
@@ -18,6 +18,7 @@ package com.android.inputmethod.latin;
import android.content.ContentResolver;
import android.content.Context;
+import android.content.res.AssetFileDescriptor;
import android.net.Uri;
import android.text.TextUtils;
@@ -96,9 +97,9 @@ public class BinaryDictionaryFileDumper {
// file.
final ContentResolver resolver = context.getContentResolver();
final Uri dictionaryPackUri = getProviderUri(locale);
- final InputStream stream = resolver.openInputStream(dictionaryPackUri);
- if (null == stream) return null;
- return copyFileTo(stream, getCacheFileNameForLocale(locale, context));
+ final AssetFileDescriptor afd = resolver.openAssetFileDescriptor(dictionaryPackUri, "r");
+ if (null == afd) return null;
+ return copyFileTo(afd.createInputStream(), getCacheFileNameForLocale(locale, context));
}
/**
@@ -128,6 +129,8 @@ public class BinaryDictionaryFileDumper {
/**
* Copies the data in an input stream to a target file, creating the file if necessary and
* overwriting it if it already exists.
+ * @param input the stream to be copied.
+ * @param outputFileName the name of a file to copy the data to. It is created if necessary.
*/
private static String copyFileTo(final InputStream input, final String outputFileName)
throws FileNotFoundException, IOException {