read from InputStream instead of ByteArrayInputStream