aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2019-07-17 20:42:54 +0200
committerChristian Schneppe <christian@pix-art.de>2019-07-17 20:42:54 +0200
commitc88523b1b84e9226e524e8d9b7ef6987118cd2cd (patch)
treef7bb3006be1122b6ce97f1c3df807e3c2038597c /src/main/java
parent00334edc6f53cf49298f23b4db87e843d1f56542 (diff)
use helper method to close socket
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/de/pixart/messenger/parser/MessageParser.java2
-rw-r--r--src/main/java/de/pixart/messenger/persistance/FileBackend.java4
-rw-r--r--src/main/java/de/pixart/messenger/xml/XmlReader.java10
-rw-r--r--src/main/java/de/pixart/messenger/xmpp/XmppConnection.java13
4 files changed, 14 insertions, 15 deletions
diff --git a/src/main/java/de/pixart/messenger/parser/MessageParser.java b/src/main/java/de/pixart/messenger/parser/MessageParser.java
index b3bcc504a..a0080e4da 100644
--- a/src/main/java/de/pixart/messenger/parser/MessageParser.java
+++ b/src/main/java/de/pixart/messenger/parser/MessageParser.java
@@ -719,7 +719,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
} else {
serverMsgIdUpdated = false;
}
- Log.d(Config.LOGTAG, "skipping duplicate message with " + message.getCounterpart() + ". serverMsgIdUpdated=" + Boolean.toString(serverMsgIdUpdated));
+ Log.d(Config.LOGTAG, "skipping duplicate message with " + message.getCounterpart() + ". serverMsgIdUpdated=" + serverMsgIdUpdated);
return;
}
}
diff --git a/src/main/java/de/pixart/messenger/persistance/FileBackend.java b/src/main/java/de/pixart/messenger/persistance/FileBackend.java
index 9386deca4..063ff50a0 100644
--- a/src/main/java/de/pixart/messenger/persistance/FileBackend.java
+++ b/src/main/java/de/pixart/messenger/persistance/FileBackend.java
@@ -1351,7 +1351,7 @@ public class FileBackend {
return getFile(message).exists();
}
- public static void close(Closeable stream) {
+ public static void close(final Closeable stream) {
if (stream != null) {
try {
stream.close();
@@ -1360,7 +1360,7 @@ public class FileBackend {
}
}
- public static void close(Socket socket) {
+ public static void close(final Socket socket) {
if (socket != null) {
try {
socket.close();
diff --git a/src/main/java/de/pixart/messenger/xml/XmlReader.java b/src/main/java/de/pixart/messenger/xml/XmlReader.java
index a67442f49..6447f12ef 100644
--- a/src/main/java/de/pixart/messenger/xml/XmlReader.java
+++ b/src/main/java/de/pixart/messenger/xml/XmlReader.java
@@ -6,14 +6,15 @@ import android.util.Xml;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
+import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import de.pixart.messenger.Config;
-public class XmlReader {
- private XmlPullParser parser;
+public class XmlReader implements Closeable {
+ private final XmlPullParser parser;
private InputStream is;
public XmlReader() {
@@ -48,6 +49,11 @@ public class XmlReader {
}
}
+ @Override
+ public void close() {
+ this.is = null;
+ }
+
public Tag readTag() throws IOException {
try {
while (this.is != null && parser.next() != XmlPullParser.END_DOCUMENT) {
diff --git a/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java b/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java
index 9493b260d..70ae1bc1b 100644
--- a/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java
+++ b/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java
@@ -1567,15 +1567,8 @@ public class XmppConnection implements Runnable {
}
private void forceCloseSocket() {
- if (socket != null) {
- try {
- socket.close();
- } catch (Exception e) {
- Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": exception " + e.getMessage() + " during force close");
- }
- } else {
- Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": socket was null during force close");
- }
+ FileBackend.close(this.socket);
+ FileBackend.close(this.tagReader);
}
public void interrupt() {
@@ -1586,7 +1579,7 @@ public class XmppConnection implements Runnable {
public void disconnect(final boolean force) {
interrupt();
- Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": disconnecting force=" + Boolean.toString(force));
+ Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": disconnecting force=" + force);
if (force) {
forceCloseSocket();
} else {