aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java
diff options
context:
space:
mode:
authorJean Chalard <jchalard@google.com>2011-08-16 21:35:52 +0900
committerJean Chalard <jchalard@google.com>2011-08-18 15:11:19 +0900
commit80e0bf04292867ddc769aca75ebaee817b95a941 (patch)
tree37b9bf7ef0951415a2210a4a758c836e1ce0a552 /java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java
parent961453c3b3a8eb3aefb2cebdbcc315c98c2abbd4 (diff)
downloadlatinime-80e0bf04292867ddc769aca75ebaee817b95a941.tar.gz
latinime-80e0bf04292867ddc769aca75ebaee817b95a941.tar.xz
latinime-80e0bf04292867ddc769aca75ebaee817b95a941.zip
Exception refactoring
Now that the dictionary pack can return several files, it's better to handle IO exceptions for each file rather than globally. This also will help with next implementation steps. Bug: 5095140 Change-Id: I5ed135ad2ad4f55f61f9b3f92c48a35d5c24bdb2
Diffstat (limited to 'java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java')
-rw-r--r--java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java29
1 files changed, 19 insertions, 10 deletions
diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java b/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java
index 3da670e2e..ed5f83b3b 100644
--- a/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java
+++ b/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java
@@ -98,23 +98,32 @@ public class BinaryDictionaryFileDumper {
* @throw IOException if the provider-returned data could not be read.
*/
public static List<AssetFileAddress> cacheDictionariesFromContentProvider(final Locale locale,
- final Context context) throws FileNotFoundException, IOException {
+ final Context context) {
final ContentResolver resolver = context.getContentResolver();
final List<String> idList = getDictIdList(locale, context);
final List<AssetFileAddress> fileAddressList = new ArrayList<AssetFileAddress>();
for (String id : idList) {
final Uri wordListUri = getProviderUri(id);
- final AssetFileDescriptor afd =
- resolver.openAssetFileDescriptor(wordListUri, "r");
+ AssetFileDescriptor afd = null;
+ try {
+ afd = resolver.openAssetFileDescriptor(wordListUri, "r");
+ } catch (FileNotFoundException e) {
+ // leave null inside afd and continue
+ }
if (null == afd) continue;
- final String fileName = copyFileTo(afd.createInputStream(),
- BinaryDictionaryGetter.getCacheFileName(id, locale, context));
- afd.close();
- if (0 >= resolver.delete(wordListUri, null, null)) {
- // I'd rather not print the word list ID to the log here out of security concerns
- Log.e(TAG, "Could not have the dictionary pack delete a word list");
+ try {
+ final String fileName = copyFileTo(afd.createInputStream(),
+ BinaryDictionaryGetter.getCacheFileName(id, locale, context));
+ afd.close();
+ if (0 >= resolver.delete(wordListUri, null, null)) {
+ // I'd rather not print the word list ID to the log out of security concerns
+ Log.e(TAG, "Could not have the dictionary pack delete a word list");
+ }
+ fileAddressList.add(AssetFileAddress.makeFromFileName(fileName));
+ } catch (IOException e) {
+ // Can't read the file for some reason. Continue onto the next file.
+ Log.e(TAG, "Cannot read a word list from the dictionary pack : " + e);
}
- fileAddressList.add(AssetFileAddress.makeFromFileName(fileName));
}
return fileAddressList;
}