From 06aac453eac0d35c320bddb5421f0da50ddf338a Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Sat, 11 Jul 2020 17:35:41 +0530 Subject: [PATCH] Use IOUtils.close(). --- .../Backends/BluetoothBackend/BluetoothLinkProvider.java | 3 ++- src/org/kde/kdeconnect/NetworkPacket.java | 5 ++--- .../Plugins/SharePlugin/CompositeReceiveFileJob.java | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/org/kde/kdeconnect/Backends/BluetoothBackend/BluetoothLinkProvider.java b/src/org/kde/kdeconnect/Backends/BluetoothBackend/BluetoothLinkProvider.java index ddff1e48..9c1076af 100644 --- a/src/org/kde/kdeconnect/Backends/BluetoothBackend/BluetoothLinkProvider.java +++ b/src/org/kde/kdeconnect/Backends/BluetoothBackend/BluetoothLinkProvider.java @@ -33,6 +33,7 @@ import android.os.Build; import android.os.Parcelable; import android.util.Log; +import org.apache.commons.io.IOUtils; import org.kde.kdeconnect.Backends.BaseLinkProvider; import org.kde.kdeconnect.Device; import org.kde.kdeconnect.NetworkPacket; @@ -230,7 +231,7 @@ public class BluetoothLinkProvider extends BaseLinkProvider { } catch (Exception e) { synchronized (sockets) { sockets.remove(socket.getRemoteDevice()); - if (connection != null) connection.close(); + IOUtils.close(connection); } throw e; } diff --git a/src/org/kde/kdeconnect/NetworkPacket.java b/src/org/kde/kdeconnect/NetworkPacket.java index 3e628698..815fea76 100644 --- a/src/org/kde/kdeconnect/NetworkPacket.java +++ b/src/org/kde/kdeconnect/NetworkPacket.java @@ -23,6 +23,7 @@ package org.kde.kdeconnect; import android.content.Context; import android.util.Log; +import org.apache.commons.io.IOUtils; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -361,9 +362,7 @@ public class NetworkPacket { public void close() { //TODO: If socket only close socket if that also closes the streams that is try { - if (inputStream != null) { - inputStream.close(); - } + IOUtils.close(inputStream); } catch(IOException ignored) {} try { diff --git a/src/org/kde/kdeconnect/Plugins/SharePlugin/CompositeReceiveFileJob.java b/src/org/kde/kdeconnect/Plugins/SharePlugin/CompositeReceiveFileJob.java index bd995ff1..6c2c9299 100644 --- a/src/org/kde/kdeconnect/Plugins/SharePlugin/CompositeReceiveFileJob.java +++ b/src/org/kde/kdeconnect/Plugins/SharePlugin/CompositeReceiveFileJob.java @@ -32,6 +32,7 @@ import androidx.core.content.ContextCompat; import androidx.core.content.FileProvider; import androidx.documentfile.provider.DocumentFile; +import org.apache.commons.io.IOUtils; import org.kde.kdeconnect.Device; import org.kde.kdeconnect.Helpers.FilesHelper; import org.kde.kdeconnect.Helpers.MediaStoreHelper; @@ -244,10 +245,9 @@ public class CompositeReceiveFileJob extends BackgroundJob { } finally { closeAllInputStreams(); networkPacketList.clear(); - if (outputStream != null) { - try { - outputStream.close(); - } catch (IOException ignored) {} + try { + IOUtils.close(outputStream); + } catch (IOException ignored) { } } }