How does a PipedInputStream read from a PipedOutputStream? Is it using toString() or is there some hidden magic to access a private member variable?
How does a PipedInputStream read from a PipedOutputStream ? Is it using toString() or
Share
PipedOutputStream.write(int byte)will simply call theprotectedmethodPipedInputStream.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
PipedInputStreamis notprivatebutprotectedand therefore accessible in the same way as theprotectedreceive()methods. ButPipedOutputStreamplays fair and does not access it directly.This works of course, because
protectedmethods and fields are accessible not only by deriving classes but by the complete package as shown in Wikipedia.No need for “magic” like “toString”.