Shevek (shevek) wrote,

We have derived the axioms of Java OutputStreams. They are far more subtle than they appear.

  • Any OutputStream must be safe against double-close.
  • Any buffering I/O layer must flush before close IF the close is not a no-op or double-close.

The options are:

  • Double-close is invalid.
  • The user is required to flush a buffer before close.

The interesting question is:

May flush() throw an IOException if the stream is closed, even if there is no buffered data to send?

The two axioms above make this question answerable either way. It doesn't matter. If you're closing, close all underlying streams you have access to, even if you then go on to close a network layer which has pointers to inner/filtered streams within them; it will be safe.

  • (no subject)

    I have yet to read a Java vs python comparison which was written by anyone with any serious enterprise development experience. If enterprises were…

  • (no subject)

    Today I was browsing my screenshots, and I found that I had failed the UK citizenship test. I took it again, just for fun, and failed with flying…

  • (no subject)

    Nobody in the USA has heard of Flanders and Swann. If the country had an editor, I would write to him to express my unmitigated disgust.

  • Post a new comment


    default userpic

    Your reply will be screened

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.