Reputation: 10203
How does a PipedInputStream
read from a PipedOutputStream
? Is it using toString()
or is there some hidden magic to access a private
member variable?
Upvotes: 0
Views: 564
Reputation: 66263
PipedOutputStream.write(int byte)
will simply call the protected
method PipedInputStream.receive(int byte)
which in turn will simply fill its own buffer. Same thing for the bulk read/write methods.
Please note that the internal buffer in PipedInputStream
is not private
but protected
and therefore accessible in the same way as the protected
receive()
methods. But PipedOutputStream
plays fair and does not access it directly.
This works of course, because protected
methods and fields are accessible not only by deriving classes but by the complete package as shown in Wikipedia.
No need for "magic" like "toString".
Upvotes: 2
Reputation: 533530
Normally you have a background thread which reads from the OutputStream and writes what it read to the PipedInputStream until it is finished.
Upvotes: 0