dromodel
dromodel

Reputation: 10203

How does PipedInputStream read from an OutputStream?

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

Answers (2)

A.H.
A.H.

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

Peter Lawrey
Peter Lawrey

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

Related Questions