Re: How to parse and manipulate a binary stream



"topcat.nyc@xxxxxxxxxxxxxx" <topcat.nyc@xxxxxxxxxxxxxx> writes:

Apologies in advance if my question is silly or trivial. I'm trying to
write a servlet that reads data from another source in byte[] form and,
having parsed this data stream and made a couple of modifications,
sends the modified data to an appropriate application whereby it can be
rendered in Excel or PDF format.

What I need to find out is how I can parse the incoming data, detect
certain string patterns in the data, and manipulate that information to
generate a new data stream.


Not a trivial question, exactly, but a bit on the
vague side. It's difficult for me to tell what you're
having difficultly with.


I'm going to assume that you're stuck getting started.

First, you need to read binary data from a source. That's
exactly the job of an InputStream. It has a read() method
that lets to read directly into a byte array.

To parse that a portion of a byte[] as a String, you can
just use the constructors in the String class.

To write the output, you need an OutputStream. You may want
to subclass it, and write a write() that asks for its next
byte of output from the object responsible for doing the
search-and-replace manipulation.


--
Mark Jeffcoat
Austin, TX
.



Relevant Pages

  • Re: Bullet proof passing numeric values from NMEA data stream.
    ... and NMEA data stream ascii numeric strings. ... def despace: ... Once you've built the character tables, the translate function itself is ... Most of the time you should use string methods, ...
    (comp.lang.python)
  • Re: Read in mixed data
    ... it will read in the string and store it as numbers. ... Then I define the first strings as the first three characters converted ... It looks like all the data stream in with no spaces or delimiters. ...
    (comp.soft-sys.matlab)
  • Re: MScomm controls
    ... > following string that's in the receive buffer? ... Dim Receive as String ... Dim V1 as String, V2 as String ... The first 3 bytes of the data stream are probably bit level status ...
    (microsoft.public.vb.general.discussion)
  • Re: Hex string conversion
    ... then it already is an ASCII text string. ... And if the data stream contains the characters that the poster indicated ...
    (microsoft.public.vb.general.discussion)