Close ContentResolver InputStream

This commit is contained in:
Sean Owen 2014-04-22 18:40:55 +01:00
parent 35e13989af
commit a9cf1e91ec

View file

@ -187,8 +187,9 @@ final class QRCodeEncoder {
}
byte[] vcard;
String vcardString;
InputStream stream = null;
try {
InputStream stream = activity.getContentResolver().openInputStream(uri);
stream = activity.getContentResolver().openInputStream(uri);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[2048];
int bytesRead;
@ -199,6 +200,14 @@ final class QRCodeEncoder {
vcardString = new String(vcard, 0, vcard.length, "UTF-8");
} catch (IOException ioe) {
throw new WriterException(ioe);
} finally {
if (stream != null) {
try {
stream.close();
} catch (IOException e) {
// continue
}
}
}
Log.d(TAG, "Encoding share intent content:");
Log.d(TAG, vcardString);