null out the output stream when closed and check for this when writing to avoid the...