Having two InputStreams in Java, is there a way to merge them so you end with one InputStream that gives you the output of both streams? How?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
As commented, it’s not clear what you mean by merge.
Taking available input ‘randomly’ from either is complicated by
InputStream.availablenot necessarily giving you a useful answer and blocking behaviour of streams. You would need two threads to be reading from the streams and then passing back data through, say,java.io.Piped(In|Out)putStream(although those classes have issues). Alternatively for some types of stream it may be possible to use a different interface, for instancejava.nionon-blocking channels.If you want the full contents of the first input stream followed by the second:
new java.io.SequenceInputStream(s1, s2).