Loading java/src/com/android/inputmethod/dictionarypack/MetadataDbHelper.java +15 −11 Original line number Diff line number Diff line Loading @@ -572,7 +572,8 @@ public class MetadataDbHelper extends SQLiteOpenHelper { * If several clients use the same metadata URL, we know to only download it once, and * dispatch the update process across all relevant clients when the download ends. This means * several clients may share a single download ID if they share a metadata URI. * The dispatching is done in {@link UpdateHandler#downloadFinished(Context, Intent)}, which * The dispatching is done in * {@link UpdateHandler#downloadFinished(Context, android.content.Intent)}, which * finds out about the list of relevant clients by calling this method. * * @param context a context instance to open the databases Loading Loading @@ -863,17 +864,20 @@ public class MetadataDbHelper extends SQLiteOpenHelper { r.getAsString(WORDLISTID_COLUMN), Integer.toString(STATUS_INSTALLED) }, null, null, null); try { if (c.moveToFirst()) { // There should never be more than one file, but if there are, it's a bug // and we should remove them all. I think it might happen if the power of the // phone is suddenly cut during an update. // and we should remove them all. I think it might happen if the power of // the phone is suddenly cut during an update. final int filenameIndex = c.getColumnIndex(LOCAL_FILENAME_COLUMN); do { Utils.l("Setting for removal", c.getString(filenameIndex)); filenames.add(c.getString(filenameIndex)); } while (c.moveToNext()); } } finally { c.close(); } r.put(STATUS_COLUMN, STATUS_INSTALLED); db.beginTransactionNonExclusive(); // Delete all old entries. There should never be any stalled entries, but if Loading java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java +27 −14 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ import com.android.inputmethod.latin.DictionaryInfoUtils.DictionaryInfo; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.Closeable; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; Loading Loading @@ -319,20 +320,12 @@ public final class BinaryDictionaryFileDumper { // Try the next method. } finally { // Ignore exceptions while closing files. try { if (null != afd) afd.close(); if (null != inputStream) inputStream.close(); if (null != uncompressedStream) uncompressedStream.close(); if (null != decryptedStream) decryptedStream.close(); if (null != bufferedInputStream) bufferedInputStream.close(); } catch (Exception e) { Log.e(TAG, "Exception while closing a file descriptor", e); } try { if (null != bufferedOutputStream) bufferedOutputStream.close(); } catch (Exception e) { Log.e(TAG, "Exception while closing a file", e); } closeAssetFileDescriptorAndReportAnyException(afd); closeCloseableAndReportAnyException(inputStream); closeCloseableAndReportAnyException(uncompressedStream); closeCloseableAndReportAnyException(decryptedStream); closeCloseableAndReportAnyException(bufferedInputStream); closeCloseableAndReportAnyException(bufferedOutputStream); } } Loading @@ -352,6 +345,26 @@ public final class BinaryDictionaryFileDumper { } } // Ideally the two following methods should be merged, but AssetFileDescriptor does not // implement Closeable although it does implement #close(), and Java does not have // structural typing. private static void closeAssetFileDescriptorAndReportAnyException( final AssetFileDescriptor file) { try { if (null != file) file.close(); } catch (Exception e) { Log.e(TAG, "Exception while closing a file", e); } } private static void closeCloseableAndReportAnyException(final Closeable file) { try { if (null != file) file.close(); } catch (Exception e) { Log.e(TAG, "Exception while closing a file", e); } } /** * Queries a content provider for word list data for some locale and cache the returned files * Loading Loading
java/src/com/android/inputmethod/dictionarypack/MetadataDbHelper.java +15 −11 Original line number Diff line number Diff line Loading @@ -572,7 +572,8 @@ public class MetadataDbHelper extends SQLiteOpenHelper { * If several clients use the same metadata URL, we know to only download it once, and * dispatch the update process across all relevant clients when the download ends. This means * several clients may share a single download ID if they share a metadata URI. * The dispatching is done in {@link UpdateHandler#downloadFinished(Context, Intent)}, which * The dispatching is done in * {@link UpdateHandler#downloadFinished(Context, android.content.Intent)}, which * finds out about the list of relevant clients by calling this method. * * @param context a context instance to open the databases Loading Loading @@ -863,17 +864,20 @@ public class MetadataDbHelper extends SQLiteOpenHelper { r.getAsString(WORDLISTID_COLUMN), Integer.toString(STATUS_INSTALLED) }, null, null, null); try { if (c.moveToFirst()) { // There should never be more than one file, but if there are, it's a bug // and we should remove them all. I think it might happen if the power of the // phone is suddenly cut during an update. // and we should remove them all. I think it might happen if the power of // the phone is suddenly cut during an update. final int filenameIndex = c.getColumnIndex(LOCAL_FILENAME_COLUMN); do { Utils.l("Setting for removal", c.getString(filenameIndex)); filenames.add(c.getString(filenameIndex)); } while (c.moveToNext()); } } finally { c.close(); } r.put(STATUS_COLUMN, STATUS_INSTALLED); db.beginTransactionNonExclusive(); // Delete all old entries. There should never be any stalled entries, but if Loading
java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java +27 −14 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ import com.android.inputmethod.latin.DictionaryInfoUtils.DictionaryInfo; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.Closeable; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; Loading Loading @@ -319,20 +320,12 @@ public final class BinaryDictionaryFileDumper { // Try the next method. } finally { // Ignore exceptions while closing files. try { if (null != afd) afd.close(); if (null != inputStream) inputStream.close(); if (null != uncompressedStream) uncompressedStream.close(); if (null != decryptedStream) decryptedStream.close(); if (null != bufferedInputStream) bufferedInputStream.close(); } catch (Exception e) { Log.e(TAG, "Exception while closing a file descriptor", e); } try { if (null != bufferedOutputStream) bufferedOutputStream.close(); } catch (Exception e) { Log.e(TAG, "Exception while closing a file", e); } closeAssetFileDescriptorAndReportAnyException(afd); closeCloseableAndReportAnyException(inputStream); closeCloseableAndReportAnyException(uncompressedStream); closeCloseableAndReportAnyException(decryptedStream); closeCloseableAndReportAnyException(bufferedInputStream); closeCloseableAndReportAnyException(bufferedOutputStream); } } Loading @@ -352,6 +345,26 @@ public final class BinaryDictionaryFileDumper { } } // Ideally the two following methods should be merged, but AssetFileDescriptor does not // implement Closeable although it does implement #close(), and Java does not have // structural typing. private static void closeAssetFileDescriptorAndReportAnyException( final AssetFileDescriptor file) { try { if (null != file) file.close(); } catch (Exception e) { Log.e(TAG, "Exception while closing a file", e); } } private static void closeCloseableAndReportAnyException(final Closeable file) { try { if (null != file) file.close(); } catch (Exception e) { Log.e(TAG, "Exception while closing a file", e); } } /** * Queries a content provider for word list data for some locale and cache the returned files * Loading