HI all,
I have an application that recieves a rather large ammount of data
through a serial connection. Since serial connections are rather slow
the data takes a fair while to recieve (10-90 sec).
To show the user that something is indeed happening I print the data
out on the screen as it comes in (it is a log, so it makes sense to
display it). Now the program gives the user the option of parsing the
log and mark certain things with colours, and and such.
Anyway, at present I display all data unparsed, and then if the user
selected to parse it I clear the screen once all data is recieved and
the put the parsed version on the screen.
I would like to parse the data pretty much as it comes in. Any
suggestions on how to do that?
The problem is that regexp is basically neccesary as I for one thing
have to detect which rows (terminated with \r\n) contains alarms, and
if they contain alarms, which alarmnumer it happens to be. From my
understanding of regexp in java I can not run a matcher (several
matchers in my case) on something while I append data "to the other
end" (for clearity, I would only append data to the end of the buffer
if it is not currently in use by some other part of the program,
simple thread safty aplies)
Any suggestions?
Any help is greatly appreciated!
regards
Daniel
Andrew Thompson - 12 Oct 2005 07:18 GMT
> ...From my
> understanding of regexp in java I can not run a matcher (several
> matchers in my case) on something while I append data "to the other
> end"
No, but if you (in a separate thread) make a copy of the
current data to a String, a regexp (split(), StringTokenizer)
can work happily with that. You might present 'raw'
output in one window, with 'parsed' data ..slightly
delayed, in another.
HTH
Daniel - 12 Oct 2005 08:12 GMT
Thanks!
It is amazing how sometimes the most simple and efficent ideas just
slip by you like that.
What I do now is that I recive a chunk of data, put it into my
stringbuffer, and if the buffer contains \r\n I split it so I keep the
piece after \r\n and the other piece I "send of for parsing" it works
remarkably well.
thanks!
daniel
>> ...From my
>> understanding of regexp in java I can not run a matcher (several
[quoted text clipped - 8 lines]
>
>HTH
Roedy Green - 12 Oct 2005 08:07 GMT
>I would like to parse the data pretty much as it comes in. Any
>suggestions on how to do that?
[quoted text clipped - 6 lines]
>if it is not currently in use by some other part of the program,
>simple thread safty aplies)
Break the stream into lines. Feed each line one at a time to the
regex.
You probably can get away with a single thread that reads until it
finds a line, then does a regex, then goes back to finding the next
line. You might even use a Reader to do that eol parsing for you.
So long as your socket is well buffered you should keep up and
effectively overlap reading and processing.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.