mirror of
https://github.com/M66B/FairEmail.git
synced 2026-01-02 19:10:11 +01:00
use try-with-resources
This commit is contained in:
@@ -1122,16 +1122,14 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
||||
if (!TextUtils.isEmpty(email))
|
||||
edit.putExtra(ContactsContract.Intents.Insert.EMAIL, email);
|
||||
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
ContentResolver resolver = context.getContentResolver();
|
||||
cursor = resolver.query(ContactsContract.CommonDataKinds.Email.CONTENT_URI,
|
||||
new String[]{
|
||||
ContactsContract.CommonDataKinds.Photo.CONTACT_ID,
|
||||
ContactsContract.Contacts.LOOKUP_KEY
|
||||
},
|
||||
ContactsContract.CommonDataKinds.Email.ADDRESS + " = ?",
|
||||
new String[]{email}, null);
|
||||
ContentResolver resolver = context.getContentResolver();
|
||||
try (Cursor cursor = resolver.query(ContactsContract.CommonDataKinds.Email.CONTENT_URI,
|
||||
new String[]{
|
||||
ContactsContract.CommonDataKinds.Photo.CONTACT_ID,
|
||||
ContactsContract.Contacts.LOOKUP_KEY
|
||||
},
|
||||
ContactsContract.CommonDataKinds.Email.ADDRESS + " = ?",
|
||||
new String[]{email}, null)) {
|
||||
if (cursor != null && cursor.moveToNext()) {
|
||||
int colContactId = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Photo.CONTACT_ID);
|
||||
int colLookupKey = cursor.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY);
|
||||
@@ -1147,9 +1145,6 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
||||
edit.setAction(Intent.ACTION_INSERT);
|
||||
edit.setType(ContactsContract.Contacts.CONTENT_TYPE);
|
||||
}
|
||||
} finally {
|
||||
if (cursor != null)
|
||||
cursor.close();
|
||||
}
|
||||
|
||||
PackageManager pm = context.getPackageManager();
|
||||
@@ -1375,11 +1370,8 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
||||
String cid = '<' + src.substring(4) + '>';
|
||||
EntityAttachment attachment = DB.getInstance(context).attachment().getAttachment(id, cid);
|
||||
if (attachment != null && attachment.available) {
|
||||
InputStream is = null;
|
||||
try {
|
||||
File file = EntityAttachment.getFile(context, attachment.id);
|
||||
|
||||
is = new BufferedInputStream(new FileInputStream(file));
|
||||
File file = EntityAttachment.getFile(context, attachment.id);
|
||||
try (InputStream is = new BufferedInputStream(new FileInputStream(file))) {
|
||||
byte[] bytes = new byte[(int) file.length()];
|
||||
if (is.read(bytes) != bytes.length)
|
||||
throw new IOException("length");
|
||||
@@ -1391,9 +1383,6 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
||||
sb.append(Base64.encodeToString(bytes, Base64.DEFAULT));
|
||||
|
||||
img.attr("src", sb.toString());
|
||||
} finally {
|
||||
if (is != null)
|
||||
is.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user