Merge "Exception refactoring"

This commit is contained in:
Jean Chalard 2011-08-18 02:36:42 -07:00 committed by Android (Google) Code Review
commit 5ba5ff9b80
2 changed files with 29 additions and 27 deletions

View file

@ -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;
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 here out of security concerns
// 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);
}
}
return fileAddressList;
}

View file

@ -237,7 +237,7 @@ class BinaryDictionaryGetter {
*/
public static List<AssetFileAddress> getDictionaryFiles(final Locale locale,
final Context context, final int fallbackResId) {
try {
// cacheDictionariesFromContentProvider returns the list of files it copied to local
// storage, but we don't really care about what was copied NOW: what we want is the
// list of everything we ever cached, so we ignore the return value.
@ -246,14 +246,7 @@ class BinaryDictionaryGetter {
if (null != cachedDictionaryList) {
return cachedDictionaryList;
}
// If the list is null, fall through and return the fallback
} catch (FileNotFoundException e) {
Log.e(TAG, "Unable to create dictionary file from provider for locale "
+ locale.toString() + ": falling back to internal dictionary");
} catch (IOException e) {
Log.e(TAG, "Unable to read source data for locale "
+ locale.toString() + ": falling back to internal dictionary");
}
final AssetFileAddress fallbackAsset = loadFallbackResource(context, fallbackResId,
locale);
if (null == fallbackAsset) return null;