Skip to content

Commit 9f7c835

Browse files
committed
refactor: simplified code
1 parent ca724dd commit 9f7c835

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

app/src/main/java/io/pslab/communication/SocketClient.java

+4-9
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,13 @@
99

1010
public class SocketClient {
1111

12-
public static final String TAG = "SocketClient";
13-
private static SocketClient socketClient = null;
12+
private static final String TAG = SocketClient.class.getSimpleName();
13+
private static SocketClient socketClient;
1414
private Socket socket;
1515
private OutputStream outputStream;
1616
private InputStream inputStream;
1717
private boolean isConnected = false;
1818

19-
public static final int DEFAULT_READ_BUFFER_SIZE = 32 * 1024;
20-
21-
private byte[] buffer = new byte[DEFAULT_READ_BUFFER_SIZE];
22-
2319
private byte[] receivedData;
2420

2521
private SocketClient() {
@@ -60,14 +56,13 @@ public synchronized int read(int bytesToBeRead) throws IOException {
6056
int readNow;
6157
Log.v(TAG, "To read : " + bytesToBeRead);
6258
int bytesToBeReadTemp = bytesToBeRead;
63-
receivedData = new byte[DEFAULT_READ_BUFFER_SIZE];
59+
receivedData = new byte[bytesToBeRead];
6460
while (numBytesRead < bytesToBeRead) {
65-
readNow = inputStream.read(buffer, 0, bytesToBeReadTemp);
61+
readNow = inputStream.read(receivedData, numBytesRead, bytesToBeReadTemp);
6662
if (readNow <= 0) {
6763
Log.e(TAG, "Read Error: " + bytesToBeReadTemp);
6864
return numBytesRead;
6965
} else {
70-
System.arraycopy(buffer, 0, receivedData, numBytesRead, readNow);
7166
numBytesRead += readNow;
7267
bytesToBeReadTemp -= readNow;
7368
}

0 commit comments

Comments
 (0)