Move getInputStream call to ensure close will always be called