Write sample data onto a ByteArrayOutputStream.
ByteArrayOutputStream
Convert to byte array
Read from a ByteArrayInputStream
ByteArrayInputStream