It's quite possible to do this. I recently wrote a project which read input from multiple mice using a very similar interface. The binary data from the mice came in via file I/O.
I think buffered I/O is inappropriate here. Buffered I/O will try to fill a buffer for you, for performance reasons. But it seems that your app will be spending most of its time waiting for new characters. If you're not reading in bulk, then raw byte reads InputStream will do the trick: They will return immediately after the requested/expected number of bytes (1 in your case) have been received. In your case, after reading the >
character, you'd issue another single-byte read for the following char.
You'll need to figure out what to do with intervening characters. Once you've processed your >
and the following char, what do you want to do with any following characters that are not >
?
What I did in my app was to directly read single bytes from an InputStream
. This would block, so it had to be done in a separate Thread
that spent most of its time waiting. When the first character came in, I knew to read a handful more (just like you will), which I could then process. I had some kind of queue set up for passing this information to the rest of my app - you'll have to work out some kind of synchronization for your inter-thread communication.
EDIT: Multiple small edits to clarify points. Sorry if this ends up confusing.