@Test
public void testWriteToUnknownLength() throws Exception {

    final String message = "Message content";
    final byte[] bytes = message.getBytes(StandardCharsets.ISO_8859_1);
    final InputStreamEntity entity = new InputStreamEntity(new ByteArrayInputStream(bytes),
            ContentType.TEXT_PLAIN.withCharset(StandardCharsets.ISO_8859_1));
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    entity.writeTo(out);
    final byte[] writtenBytes = out.toByteArray();
    Assert.assertNotNull(writtenBytes);
    Assert.assertEquals(bytes.length, writtenBytes.length);
    final String s = new String(writtenBytes, StandardCharsets.ISO_8859_1.name());
    Assert.assertEquals(message, s);
}