MultiOutputStream Example
The following is an example of writing data to all bound streams using MultiOutputStream.
import std.io.*
main(): Unit {
const size = 2
/* Binds two ByteArrayStream instances to MultiOutputStream. */
let streamArr = Array<OutputStream>(size, {_ => ByteArrayStream()})
let multiOutputStream = MultiOutputStream(streamArr)
/* Writes data to MultiOutputStream. The data is written to the two bound ByteArrayStream instances at the same time. */
multiOutputStream.write("test".toArray())
/* Reads data from ByteArrayStream and verifies the result. */
for (i in 0..size) {
match (streamArr[i]) {
case v: ByteArrayStream =>
println(String.fromUtf8(v.readToEnd()))
case _ => throw Exception()
}
}
}
Running result:
test
test