regexp on changing input

Discussion in 'Java' started by Daniel, Oct 12, 2005.

  1. Daniel

    Daniel Guest

    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!

    Daniel, Oct 12, 2005
    1. Advertisements

  2. 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.

    Andrew Thompson, Oct 12, 2005
    1. Advertisements

  3. Daniel

    Roedy Green Guest

    Break the stream into lines. Feed each line one at a time to the

    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.
    Roedy Green, Oct 12, 2005
  4. Daniel

    Daniel Guest

    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.

    Daniel, Oct 12, 2005
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.