2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-31 14:15:14 +00:00

Add more usages of try-with-resources.

This commit is contained in:
Isira Seneviratne
2020-08-01 16:31:21 +05:30
committed by Albert Vaca Cintora
parent f5635a42ad
commit e79aac5b6f
2 changed files with 14 additions and 13 deletions

View File

@@ -175,14 +175,19 @@ public class BluetoothLinkProvider extends BaseLinkProvider {
}
}
ConnectionMultiplexer connection = null;
Log.i("BTLinkProvider/Server", "Received connection from " + socket.getRemoteDevice().getAddress());
//Delay to let bluetooth initialize stuff correctly
try {
Log.i("BTLinkProvider/Server", "Received connection from " + socket.getRemoteDevice().getAddress());
//Delay to let bluetooth initialize stuff correctly
Thread.sleep(500);
} catch (Exception e) {
synchronized (sockets) {
sockets.remove(socket.getRemoteDevice());
}
throw e;
}
connection = new ConnectionMultiplexer(socket);
try (ConnectionMultiplexer connection = new ConnectionMultiplexer(socket)) {
OutputStream outputStream = connection.getDefaultOutputStream();
InputStream inputStream = connection.getDefaultInputStream();
@@ -219,7 +224,6 @@ public class BluetoothLinkProvider extends BaseLinkProvider {
} catch (Exception e) {
synchronized (sockets) {
sockets.remove(socket.getRemoteDevice());
IOUtils.close(connection);
}
throw e;
}

View File

@@ -36,6 +36,8 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import kotlin.text.Charsets;
public class ContactsHelper {
static final String LOG_TAG = "ContactsHelper";
@@ -155,15 +157,10 @@ public class ContactsHelper {
Uri vcardURI = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_VCARD_URI, lookupKey);
try (InputStream input = context.getContentResolver().openInputStream(vcardURI)) {
if (input == null)
{
if (input == null) {
throw new NullPointerException("ContentResolver did not give us a stream for the VCard for uID " + ID);
}
final Reader reader = new InputStreamReader(input);
final List<String> lines = IOUtils.readLines(reader);
reader.close();
final List<String> lines = IOUtils.readLines(input, Charsets.UTF_8);
toReturn.put(ID, new VCardBuilder(StringUtils.join(lines, '\n')));
} catch (IOException e) {
// If you are experiencing this, please open a bug report indicating how you got here