fix too early closing of InputStream