1

I am reading data from a BluetoothSocket (SPP) and I want to read it using a buffered reader.

// Written out of mind. May contain a typo.
myBluetoothSocket s = ...;
InputStream a = s.getInputStream();
InputStreamReader b = new InputStreamReader(a);
BufferedReader c = new BufferedReader(b);
Log.d("####"+c.ready());

At one of my phones, it is working.

On another phone, c.ready() is blocking. The documentation does not mention that this function may block. If I turn off the remote Bluetooth device, nothing does change - the thread stays blocked.

Daniel Marschall
  • 3,739
  • 2
  • 28
  • 67
  • http://stackoverflow.com/questions/11273786/how-can-i-read-from-a-bufferedreader-in-java-without-blocking – sakir Dec 11 '14 at 17:18
  • 1
    This doesn't help. The method "available" returns values which cannot be trusted. The java documentation warns about it. It may not be used for trying to avoid blocking read. Indeed, I have devices where "available" is always zero or always (!) non-zero . – Daniel Marschall Dec 11 '14 at 17:46

0 Answers0