M
Martijn
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).
In code (forgive me for any mistakes):
byte[] buf;
ByteArrayInputStream istream = new ByteArrayInputStream(buf);
ByteArrayOutputStream ostream = new ByteArrayOutputStream();
// init the buffer (from file, which happens to be a component with no
input)
Comp1(ostream, istream);
buf = ostream.toByteArray(); // this invalidates the original buffer,
right?
ostream.reset();
Comp2(ostream, istream);
// etc...
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,
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).
In code (forgive me for any mistakes):
byte[] buf;
ByteArrayInputStream istream = new ByteArrayInputStream(buf);
ByteArrayOutputStream ostream = new ByteArrayOutputStream();
// init the buffer (from file, which happens to be a component with no
input)
Comp1(ostream, istream);
buf = ostream.toByteArray(); // this invalidates the original buffer,
right?
ostream.reset();
Comp2(ostream, istream);
// etc...
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,