Java real-time (9600 baud) stream parsing

Posted on 2008-11-12
Last Modified: 2013-11-23

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

Question by:dennisk1718
    LVL 51

    Expert Comment

    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

    Author Comment


    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
    LVL 51

    Accepted Solution

    if you need to match something in real time in the stream, I guess you need to write your own parser

    Featured Post

    Courses: Start Training Online With Pros, Today

    Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

    Join & Write a Comment

    Suggested Solutions

    Navigation is an important part of web design from a usability perspective. But it is often a pain when it comes to a developer’s perspective. By navigation, it often means menuing. This is less theory and more practical of how to get a specific gro…
    This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
    This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    25 Experts available now in Live!

    Get 1:1 Help Now