2
0
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:
Nicolas Fella 2018-12-24 17:50:49 +01:00
parent 03b5c769bd
commit b4df9f0cb6
2 changed files with 3 additions and 26 deletions

View File

@ -198,8 +198,7 @@ public class BluetoothLink extends BaseLink {
sendMessage(np); sendMessage(np);
if (serverSocket != null) { if (serverSocket != null) {
BluetoothSocket transferSocket = serverSocket.accept(); try (BluetoothSocket transferSocket = serverSocket.accept()) {
try {
serverSocket.close(); serverSocket.close();
int idealBufferLength = 4096; int idealBufferLength = 4096;
@ -223,11 +222,6 @@ public class BluetoothLink extends BaseLink {
} catch (Exception e) { } catch (Exception e) {
callback.onFailure(e); callback.onFailure(e);
return false; return false;
} finally {
try {
transferSocket.close();
} catch (IOException ignored) {
}
} }
} }

View File

@ -91,12 +91,8 @@ public class ContactsHelper {
} }
Uri photoUri = Uri.parse(photoId); Uri photoUri = Uri.parse(photoId);
InputStream input = null; ByteArrayOutputStream encodedPhoto = new ByteArrayOutputStream();
Base64OutputStream output = null; try (InputStream input = context.getContentResolver().openInputStream(photoUri); Base64OutputStream output = new Base64OutputStream(encodedPhoto, Base64.DEFAULT)) {
try {
ByteArrayOutputStream encodedPhoto = new ByteArrayOutputStream();
output = new Base64OutputStream(encodedPhoto, Base64.DEFAULT);
input = context.getContentResolver().openInputStream(photoUri);
byte[] buffer = new byte[1024]; byte[] buffer = new byte[1024];
int len; int len;
//noinspection ConstantConditions //noinspection ConstantConditions
@ -107,19 +103,6 @@ public class ContactsHelper {
} catch (Exception ex) { } catch (Exception ex) {
Log.e("ContactsHelper", ex.toString()); Log.e("ContactsHelper", ex.toString());
return ""; return "";
} finally {
try {
//noinspection ConstantConditions
input.close();
} catch (Exception ignored) {
}
try {
//noinspection ConstantConditions
output.close();
} catch (Exception ignored) {
}
} }
} }