Check for null input stream before attempting to close