I would like to know what is the best way to read bytes from a Java InputStream multiple times and still be efficient when the stream is very large.
Let's say I have the following code:
public void handleBytes(InputStream in) {
doStuff1(in);
doStuff2(in);
doStuff3(in);
}
where doStuff1, doStuff2 and doStuff3 all need to work on the same bytes but do different things. Also I am assuming that those functions can be asynchronous.
I know that it is possible to mark and then reset the stream but I am wondering if this is the way to go when in has a lot of data. Also if I want to have a thread worker per doStuff-X, I cannot really use reset.
Should I have a copy of the stream for each doStuff-X method? But then again I am not sure that it is going to be efficient for large amounts of data.