Commit b4df9f0c authored by Nicolas Fella's avatar Nicolas Fella
Browse files

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
parent 03b5c769
......@@ -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) {
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment