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; byte[] vcard;
String vcardString; String vcardString;
InputStream stream = null;
try { try {
InputStream stream = activity.getContentResolver().openInputStream(uri); stream = activity.getContentResolver().openInputStream(uri);
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[2048]; byte[] buffer = new byte[2048];
int bytesRead; int bytesRead;
@ -199,6 +200,14 @@ final class QRCodeEncoder {
vcardString = new String(vcard, 0, vcard.length, "UTF-8"); vcardString = new String(vcard, 0, vcard.length, "UTF-8");
} catch (IOException ioe) { } catch (IOException ioe) {
throw new WriterException(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, "Encoding share intent content:");
Log.d(TAG, vcardString); Log.d(TAG, vcardString);