rewrite InputStream to minimize any list copying