Close should only be called if the stream object exists.