As commented, it's not clear what you mean by merge.
Taking available input "randomly" from either is complicated by InputStream.available
not 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 instance java.nio
non-blocking channels.
If you want the full contents of the first input stream followed by the second: new java.io.SequenceInputStream(s1, s2)
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…