Skip to content

Commit

Permalink
#128 Close inputstream after decoding bitmap
Browse files Browse the repository at this point in the history
  • Loading branch information
davemorrissey committed Oct 13, 2015
1 parent 7d42d6c commit fc7ce78
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.net.Uri;
import android.text.TextUtils;

import java.io.InputStream;
import java.util.List;

/**
Expand Down Expand Up @@ -59,8 +60,16 @@ public Bitmap decode(Context context, Uri uri) throws Exception {
} else if (uriString.startsWith(FILE_PREFIX)) {
bitmap = BitmapFactory.decodeFile(uriString.substring(FILE_PREFIX.length()), options);
} else {
ContentResolver contentResolver = context.getContentResolver();
bitmap = BitmapFactory.decodeStream(contentResolver.openInputStream(uri), null, options);
InputStream inputStream = null;
try {
ContentResolver contentResolver = context.getContentResolver();
inputStream = contentResolver.openInputStream(uri);
bitmap = BitmapFactory.decodeStream(inputStream, null, options);
} finally {
if (inputStream != null) {
try { inputStream.close(); } catch (Exception e) { }
}
}
}
if (bitmap == null) {
throw new RuntimeException("Skia image region decoder returned null bitmap - image format may not be supported");
Expand Down

0 comments on commit fc7ce78

Please sign in to comment.