2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-30 21:55:10 +00:00

Revert "Try-with-resources on inputstreams"

This reverts commit aa776739b7
This commit is contained in:
Simon Redman
2019-04-19 05:10:11 +00:00
parent 21b97d335c
commit dc5f10c073
5 changed files with 37 additions and 36 deletions

View File

@@ -32,7 +32,6 @@ import org.json.JSONObject;
import org.kde.kdeconnect.Backends.BaseLink;
import org.kde.kdeconnect.Backends.BasePairingHandler;
import org.kde.kdeconnect.Device;
import org.kde.kdeconnect.Helpers.StringsHelper;
import org.kde.kdeconnect.NetworkPacket;
import java.io.IOException;
@@ -53,7 +52,8 @@ public class BluetoothLink extends BaseLink {
@Override
public void run() {
StringBuilder sb = new StringBuilder();
try (Reader reader = new InputStreamReader(socket.getInputStream(), StringsHelper.UTF8)) {
try {
Reader reader = new InputStreamReader(socket.getInputStream(), "UTF-8");
char[] buf = new char[512];
while (continueAccepting) {
while (sb.indexOf("\n") == -1 && continueAccepting) {

View File

@@ -35,7 +35,6 @@ import android.util.Log;
import org.kde.kdeconnect.Backends.BaseLinkProvider;
import org.kde.kdeconnect.Device;
import org.kde.kdeconnect.Helpers.StringsHelper;
import org.kde.kdeconnect.NetworkPacket;
import java.io.IOException;
@@ -188,14 +187,14 @@ public class BluetoothLinkProvider extends BaseLinkProvider {
Log.i("BTLinkProvider/Server", "Received connection from " + socket.getRemoteDevice().getAddress());
NetworkPacket np = NetworkPacket.createIdentityPacket(context);
byte[] message = np.serialize().getBytes(StringsHelper.UTF8);
byte[] message = np.serialize().getBytes("UTF-8");
outputStream.write(message);
Log.i("BTLinkProvider/Server", "Sent identity package");
// Listen for the response
StringBuilder sb = new StringBuilder();
try (Reader reader = new InputStreamReader(socket.getInputStream(), StringsHelper.UTF8)) {
Reader reader = new InputStreamReader(socket.getInputStream(), "UTF-8");
int charsRead;
char[] buf = new char[512];
while (sb.lastIndexOf("\n") == -1 && (charsRead = reader.read(buf)) != -1) {
@@ -217,8 +216,6 @@ public class BluetoothLinkProvider extends BaseLinkProvider {
addLink(identityPacket, link);
}
}
}
private class ClientRunnable extends BroadcastReceiver implements Runnable {

View File

@@ -88,7 +88,8 @@ public class LanLink extends BaseLink {
//Log.e("LanLink", "Start listening");
//Create a thread to take care of incoming data for the new socket
new Thread(() -> {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(newSocket.getInputStream(), StringsHelper.UTF8))) {
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(newSocket.getInputStream(), StringsHelper.UTF8));
while (true) {
String packet;
try {
@@ -219,7 +220,9 @@ public class LanLink extends BaseLink {
}
return true;
} catch (Exception e) {
if (callback != null) {
callback.onFailure(e);
}
return false;
} finally {
//Make sure we close the payload stream, if any

View File

@@ -93,7 +93,8 @@ public class LanLinkProvider extends BaseLinkProvider implements LanLink.LinkDis
private void tcpPacketReceived(Socket socket) {
NetworkPacket networkPacket;
try (BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()))) {
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
String message = reader.readLine();
networkPacket = NetworkPacket.unserialize(message);
//Log.e("TcpListener","Received TCP package: "+networkPacket.serialize());

View File

@@ -184,7 +184,8 @@ public class ContactsHelper {
;
StringBuilder vcardJumble = new StringBuilder();
try (BufferedReader bufferedInput = new BufferedReader(new InputStreamReader(context.getContentResolver().openInputStream(vcardURI)))) {
try (InputStream input = context.getContentResolver().openInputStream(vcardURI)) {
BufferedReader bufferedInput = new BufferedReader(new InputStreamReader(input));
String line;
while ((line = bufferedInput.readLine()) != null) {
vcardJumble.append(line).append('\n');
@@ -228,16 +229,15 @@ public class ContactsHelper {
throw new NullPointerException("ContentResolver did not give us a stream for the VCard for uID " + ID);
}
try (BufferedReader bufferedInput = new BufferedReader(new InputStreamReader(input))) {
StringBuilder vCard = new StringBuilder();
BufferedReader bufferedInput = new BufferedReader(new InputStreamReader(input));
StringBuilder vcard = new StringBuilder();
String line;
while ((line = bufferedInput.readLine()) != null) {
vCard.append(line).append('\n');
}
toReturn.put(ID, new VCardBuilder(vCard.toString()));
vcard.append(line).append('\n');
}
toReturn.put(ID, new VCardBuilder(vcard.toString()));
} catch (IOException e) {
// If you are experiencing this, please open a bug report indicating how you got here
Log.e("Contacts", "Exception while fetching vcards", e);