Skip to content

Commit

Permalink
Merge pull request #13 from shahimclt/truncate_read_data
Browse files Browse the repository at this point in the history
truncate buffer to length of data read
  • Loading branch information
whilu authored Feb 6, 2017
2 parents 2fca082 + 4b75d04 commit f408a7d
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.UUID;

import co.lujun.lmbluetoothsdk.base.BaseListener;
Expand Down Expand Up @@ -355,9 +356,14 @@ public void run() {
int bytes;
while (true) {
try {
bytes = mmInStream.read(buffer);
if (mBluetoothListener != null){
((BluetoothListener)mBluetoothListener).onReadData(mmSocket.getRemoteDevice(), buffer);
if (mmInStream.available()>0) {
bytes = mmInStream.read(buffer);
if (bytes>0) {
byte[] data = Arrays.copyOf(buffer,bytes);
if (mBluetoothListener != null) {
((BluetoothListener) mBluetoothListener).onReadData(mmSocket.getRemoteDevice(), data);
}
}
}
} catch (IOException e) {
setState(co.lujun.lmbluetoothsdk.base.State.STATE_DISCONNECTED);
Expand Down

0 comments on commit f408a7d

Please sign in to comment.