diff options
author | Romain Guy <romainguy@google.com> | 2012-12-03 10:10:22 -0800 |
---|---|---|
committer | Romain Guy <romainguy@google.com> | 2012-12-03 10:10:22 -0800 |
commit | 3614394c85da011c2899f2a8877573186707e7e4 (patch) | |
tree | ff54ede97b87da2dfc3e76ad3912650fed44ac5a /core/java | |
parent | 01a9adde7a7218906cac856207ab2b6a4d49a3f5 (diff) | |
download | frameworks_base-3614394c85da011c2899f2a8877573186707e7e4.zip frameworks_base-3614394c85da011c2899f2a8877573186707e7e4.tar.gz frameworks_base-3614394c85da011c2899f2a8877573186707e7e4.tar.bz2 |
Close InputStream after we're done reading from it
External bug #40837
Change-Id: Ic7f3fefb7aabf4d006f9928b6f67d1263f039487
Diffstat (limited to 'core/java')
-rw-r--r-- | core/java/android/widget/ImageView.java | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/core/java/android/widget/ImageView.java b/core/java/android/widget/ImageView.java index 1d465ce..e3f0960 100644 --- a/core/java/android/widget/ImageView.java +++ b/core/java/android/widget/ImageView.java @@ -40,6 +40,9 @@ import android.view.accessibility.AccessibilityEvent; import android.view.accessibility.AccessibilityNodeInfo; import android.widget.RemoteViews.RemoteView; +import java.io.IOException; +import java.io.InputStream; + /** * Displays an arbitrary image, such as an icon. The ImageView class * can load images from various sources (such as resources or content @@ -632,20 +635,27 @@ public class ImageView extends View { } } else if (ContentResolver.SCHEME_CONTENT.equals(scheme) || ContentResolver.SCHEME_FILE.equals(scheme)) { + InputStream stream = null; try { - d = Drawable.createFromStream( - mContext.getContentResolver().openInputStream(mUri), - null); + stream = mContext.getContentResolver().openInputStream(mUri); + d = Drawable.createFromStream(stream, null); } catch (Exception e) { Log.w("ImageView", "Unable to open content: " + mUri, e); + } finally { + if (stream != null) { + try { + stream.close(); + } catch (IOException e) { + Log.w("ImageView", "Unable to close content: " + mUri, e); + } + } } - } else { + } else { d = Drawable.createFromPath(mUri.toString()); } if (d == null) { - System.out.println("resolveUri failed on bad bitmap uri: " - + mUri); + System.out.println("resolveUri failed on bad bitmap uri: " + mUri); // Don't try again. mUri = null; } |