The following test fails.
@Test
public void testConversions() {
final Charset charset = Charsets.UTF_8;
final byte[] inputBytes = {37, 80, 68, 70, 45, 49, 46, 52, 13, 10, 37, -11, -28, -10, -4, 13, 10};
final String string = new String(inputBytes, charset);
final byte[] outputBytes = string.getBytes(charset);
assertArrayEquals(inputBytes, outputBytes);
}
If instead of UTF-8 charset ISO_8859_1 is used, the test passes, even with much bigger inputBytes array. Do the input and output differ because of 'variable-width' property of UTF-8?
Bonus question: Is it a true presumption that the conversions byte[] → String → byte[] will always have the same input and output byte arrays, if ISO_8859_1 is used?