mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-29 21:27:40 +00:00
Use try-with-resource
Reviewers: #kde_connect, albertvaka Reviewed By: #kde_connect, albertvaka Subscribers: kdeconnect Tags: #kde_connect Differential Revision: https://phabricator.kde.org/D17778
This commit is contained in:
parent
03b5c769bd
commit
b4df9f0cb6
@ -198,8 +198,7 @@ public class BluetoothLink extends BaseLink {
|
||||
sendMessage(np);
|
||||
|
||||
if (serverSocket != null) {
|
||||
BluetoothSocket transferSocket = serverSocket.accept();
|
||||
try {
|
||||
try (BluetoothSocket transferSocket = serverSocket.accept()) {
|
||||
serverSocket.close();
|
||||
|
||||
int idealBufferLength = 4096;
|
||||
@ -223,11 +222,6 @@ public class BluetoothLink extends BaseLink {
|
||||
} catch (Exception e) {
|
||||
callback.onFailure(e);
|
||||
return false;
|
||||
} finally {
|
||||
try {
|
||||
transferSocket.close();
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -91,12 +91,8 @@ public class ContactsHelper {
|
||||
}
|
||||
Uri photoUri = Uri.parse(photoId);
|
||||
|
||||
InputStream input = null;
|
||||
Base64OutputStream output = null;
|
||||
try {
|
||||
ByteArrayOutputStream encodedPhoto = new ByteArrayOutputStream();
|
||||
output = new Base64OutputStream(encodedPhoto, Base64.DEFAULT);
|
||||
input = context.getContentResolver().openInputStream(photoUri);
|
||||
ByteArrayOutputStream encodedPhoto = new ByteArrayOutputStream();
|
||||
try (InputStream input = context.getContentResolver().openInputStream(photoUri); Base64OutputStream output = new Base64OutputStream(encodedPhoto, Base64.DEFAULT)) {
|
||||
byte[] buffer = new byte[1024];
|
||||
int len;
|
||||
//noinspection ConstantConditions
|
||||
@ -107,19 +103,6 @@ public class ContactsHelper {
|
||||
} catch (Exception ex) {
|
||||
Log.e("ContactsHelper", ex.toString());
|
||||
return "";
|
||||
} finally {
|
||||
try {
|
||||
//noinspection ConstantConditions
|
||||
input.close();
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
|
||||
try {
|
||||
//noinspection ConstantConditions
|
||||
output.close();
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user