|
9 | 9 |
|
10 | 10 | public class SocketClient {
|
11 | 11 |
|
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; |
14 | 14 | private Socket socket;
|
15 | 15 | private OutputStream outputStream;
|
16 | 16 | private InputStream inputStream;
|
17 | 17 | private boolean isConnected = false;
|
18 | 18 |
|
19 |
| - public static final int DEFAULT_READ_BUFFER_SIZE = 32 * 1024; |
20 |
| - |
21 |
| - private byte[] buffer = new byte[DEFAULT_READ_BUFFER_SIZE]; |
22 |
| - |
23 | 19 | private byte[] receivedData;
|
24 | 20 |
|
25 | 21 | private SocketClient() {
|
@@ -60,14 +56,13 @@ public synchronized int read(int bytesToBeRead) throws IOException {
|
60 | 56 | int readNow;
|
61 | 57 | Log.v(TAG, "To read : " + bytesToBeRead);
|
62 | 58 | int bytesToBeReadTemp = bytesToBeRead;
|
63 |
| - receivedData = new byte[DEFAULT_READ_BUFFER_SIZE]; |
| 59 | + receivedData = new byte[bytesToBeRead]; |
64 | 60 | while (numBytesRead < bytesToBeRead) {
|
65 |
| - readNow = inputStream.read(buffer, 0, bytesToBeReadTemp); |
| 61 | + readNow = inputStream.read(receivedData, numBytesRead, bytesToBeReadTemp); |
66 | 62 | if (readNow <= 0) {
|
67 | 63 | Log.e(TAG, "Read Error: " + bytesToBeReadTemp);
|
68 | 64 | return numBytesRead;
|
69 | 65 | } else {
|
70 |
| - System.arraycopy(buffer, 0, receivedData, numBytesRead, readNow); |
71 | 66 | numBytesRead += readNow;
|
72 | 67 | bytesToBeReadTemp -= readNow;
|
73 | 68 | }
|
|
0 commit comments