Merge "Allow use of assets for data in the dictionary content provider."
This commit is contained in:
commit
a0efebf304
1 changed files with 6 additions and 3 deletions
|
@ -18,6 +18,7 @@ package com.android.inputmethod.latin;
|
||||||
|
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.res.AssetFileDescriptor;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
@ -96,9 +97,9 @@ public class BinaryDictionaryFileDumper {
|
||||||
// file.
|
// file.
|
||||||
final ContentResolver resolver = context.getContentResolver();
|
final ContentResolver resolver = context.getContentResolver();
|
||||||
final Uri dictionaryPackUri = getProviderUri(locale);
|
final Uri dictionaryPackUri = getProviderUri(locale);
|
||||||
final InputStream stream = resolver.openInputStream(dictionaryPackUri);
|
final AssetFileDescriptor afd = resolver.openAssetFileDescriptor(dictionaryPackUri, "r");
|
||||||
if (null == stream) return null;
|
if (null == afd) return null;
|
||||||
return copyFileTo(stream, getCacheFileNameForLocale(locale, context));
|
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
|
* Copies the data in an input stream to a target file, creating the file if necessary and
|
||||||
* overwriting it if it already exists.
|
* 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)
|
private static String copyFileTo(final InputStream input, final String outputFileName)
|
||||||
throws FileNotFoundException, IOException {
|
throws FileNotFoundException, IOException {
|
||||||
|
|
Loading…
Reference in a new issue