Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6f0b0802 authored by Paul Duffin's avatar Paul Duffin
Browse files

Switching to use try-with-resources

The Closeables.closeQuietly(Closeable) method is no longer
present in v18. This change replaces usages with the
try-with-resource pattern.

This is part of the work to upgrade Guava to version 18.

Cherry picked f43973fd

BUG: 19672715
Change-Id: I469bef916e3c570454dae19d5dc4515143ee4cdb
parent 5f35f34f
Loading
Loading
Loading
Loading
+3 −9
Original line number Diff line number Diff line
@@ -148,13 +148,9 @@ public class ContactPhotoUtils {
     */
    public static boolean savePhotoFromUriToUri(Context context, Uri inputUri, Uri outputUri,
            boolean deleteAfterSave) {
        FileOutputStream outputStream = null;
        InputStream inputStream = null;
        try {
            outputStream = context.getContentResolver()
        try (FileOutputStream outputStream = context.getContentResolver()
                 .openAssetFileDescriptor(outputUri, "rw").createOutputStream();
            inputStream = context.getContentResolver().openInputStream(
                    inputUri);
             InputStream inputStream = context.getContentResolver().openInputStream(inputUri)) {

            final byte[] buffer = new byte[16 * 1024];
            int length;
@@ -168,8 +164,6 @@ public class ContactPhotoUtils {
            Log.e(TAG, "Failed to write photo: " + inputUri.toString() + " because: " + e);
            return false;
        } finally {
            Closeables.closeQuietly(inputStream);
            Closeables.closeQuietly(outputStream);
            if (deleteAfterSave) {
                context.getContentResolver().delete(inputUri, null, null);
            }