Only close stream if non-null