Fix bug caused by multiple inputstream reads