Changed code structure for testability

Might as well just use IOUtils.copyStream here.