Re: constructing a graph (linking streams)
Martijn wrote:
Hi,
I want to create a graph where output from one component is input for the
next. The components are invoked serially, so one component needs to be
done before the next one kicks in:
+--------+ +--------+ +--------+
====> | COMP 1 | ====> | COMP 2 | ====> | COMP 3 | ====>
+--------+ +--------+ +--------+
Lets consider all streams to be byte streams to keep it simple (or char
streams if that would help). What I have done now is create an array, e.g.
byte[] buf and simply use a ByteArrayOutputStream and copy the output into
it, and create a new ByteArrayInputStream (I might be able to reset it, but
I figured the overhead would be minimal, as it was using the same buffer
anyway, so I chose to play it safe).
But this invalidates my buffer each time and requires an extra copy phase I
would like to get rid of. Any more appropriate solution available for this?
Which classes should I have a look at? Any pointers are greatly
appreciated!
Thanks for the help,
What I tend to prefer for chained parsers is to define new InputStreams
that take the previous one as a source, like so:
Step1Transformer s1t = new Step1Transformer(input);
Step2Transformer s2t = new Step2Transformer(s1t);
byte[] data = s2t.getDataHowever(); // Internally invokes s1t's parser.