Refactoring of InputStream support, with tests