@Test
public void testUnknownLengthContentToByteArray() throws Exception {

    final byte[] bytes = "Message content".getBytes(StandardCharsets.ISO_8859_1);
    final BasicHttpEntity entity = new BasicHttpEntity(new ByteArrayInputStream(bytes), -1, null);
    final byte[] bytes2 = EntityUtils.toByteArray(entity);
    Assert.assertNotNull(bytes2);
    Assert.assertEquals(bytes.length, bytes2.length);
    for (int i = 0; i < bytes.length; i++) {
        Assert.assertEquals(bytes[i], bytes2[i]);
    }
}