0

I'm using a bufferedReader to read from a FIFO queue, data is put in the FIFO queue by a C program that reads from a UART to get data (the C program isn't running yet, so I'm using echo "test" > MY_FIFO to test).

I want my java program to block until there is data, and only execute when there is data. It does this the first time, but once something is put in the fifo, fif.readLine() repeatedly returns null.

Is there any way to 'reset' the bufferedReader so that it blocks again on the next call to readLine()? The only workaround I can think of at the moment is re-initializing the reader after reading from it.

edit : The queue I am using is a FIFO queue (a file) created by a call to mkfifo()

Brydon Gibson
  • 1,179
  • 3
  • 11
  • 22
  • HF debugging your FIFO queue, all the Stream I/O based classes do block implicitly, as long as the underlying data source actually implements it *properly*. Don't blame the messenger – Durandal Feb 13 '17 at 17:50
  • I don't understand what you mean, I'm not blaming the messenger (bash in this case). I imagine that it is not blocking because it is seeing 'end of stream', which is something I don't want, I want the stream to never end. – Brydon Gibson Feb 13 '17 at 17:55
  • not sure what you are asking .... you can read this http://stackoverflow.com/questions/15521352/bufferedreader-readline-blocks . I think that you can use the `Scanner` class - see here http://stackoverflow.com/questions/24845518/scanner-nextline-blocks-when-using-inputstream-from-socket – Mzf Feb 13 '17 at 17:58
  • Is the queue maintained in memory, or are you using some kind of persistent storage medium such as a file to store the queue data? – Vince Feb 13 '17 at 18:22

0 Answers0