Could someone explain it to me ?
Why the order of creation makes any differenece ?
You must be signed in to leave a comment
18 January 2022, 12:14
As I understand it -> When wrapping InputStream into ObjectInputStream the OIS constructor has to read a header (a few first bytes of stream) in order to (I believe) make sure that the InputStream is valid. If there are no bytes written to it (and surely there are none, beacause there is not OutputStream), it waits indefinetely for them to arrive. Changing the order of creation makes sure that output stream is created before input stream and therefore the header is written to the stream).