Java real-time (9600 baud) stream parsing


I have a stream of data going by and I need to pull out some of the records. The stream is all ASCII.
The stream/record fields are delimited by slash "/".
My particular record is 256 chars and begins by a field of 6 BLANKS followed by a slash "/"
and 30 slashes "/" into the record I have an Identifier of /GH/. I then have 5 more fields delimited by "/", which marks the end of the record. There is other stuff in this stream which is useless and may, coincedentally have the same 30 s;ashes but it wil nothave the /BF/ identifier. Once I have found the target string I have to save the string from the frist 6 BLANKS to the last 5 fields.

Interesting problem....
I have loooked at split, tokenizer, etc and have found those solutions wanting because of the unusual
regex required. For example the following does not work as a recognizer:

1. Pattern p = Pattern.compile("[\\s\\s\\s\\s\\s\\s]/{30}/GH/{5}");

Thank You

Who is Participating?
ahoffmannConnect With a Mentor Commented:
if you need to match something in real time in the stream, I guess you need to write your own parser
you cannot match to a stream, you need at least read the stream 'til you identified something you want to match, then you can use a regex against the stored (rad) data not the stream
dennisk1718Author Commented:

Oh, ok...

Sure...I have a continous stream of data running by, and I need to grab some messages form that stream. I have only one chance and then it is gone. 9600bps is not too fast but...
I need a recognizer and a parser. I am stuck a little on the recognizer. I am using socket with readline currently, but it looks like I need to use a StringReader.

Are the Java I/O experts out there????

Thank You
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.