Skip to content

Commit

Permalink
Merge pull request #48 from vanniktech/close
Browse files Browse the repository at this point in the history
BluetoothConnection: Close everything separately.
  • Loading branch information
IvBaranov authored Oct 29, 2018
2 parents 94a4533 + 29b1053 commit 3e96230
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -242,21 +242,9 @@ public boolean send(String text) {
* Close the streams and socket connection.
*/
public void closeConnection() {
try {
connected = false;

if (inputStream != null) {
inputStream.close();
}

if (outputStream != null) {
outputStream.close();
}

if (socket != null) {
socket.close();
}
} catch (IOException ignored) {
}
connected = false;
Utils.close(inputStream);
Utils.close(outputStream);
Utils.close(socket);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.github.ivbaranov.rxbluetooth;

import java.io.Closeable;
import java.io.IOException;

final class Utils {
static void close(Closeable closeable) {
if (closeable != null) {
try {
closeable.close();
} catch (IOException ignored) {
// Ignored.
}
}
}

private Utils() {
throw new AssertionError("No instances.");
}
}

0 comments on commit 3e96230

Please sign in to comment.