public void testAppending() throws IOException
{
final String INPUT = "\"quo\\ted\"";
final String QUOTED = "\\\"quo\\\\ted\\\"";
SerializableString sstr = new SerializedString(INPUT);
// sanity checks first:
assertEquals(sstr.getValue(), INPUT);
assertEquals(QUOTED, new String(sstr.asQuotedChars()));
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
assertEquals(QUOTED.length(), sstr.writeQuotedUTF8(bytes));
assertEquals(QUOTED, bytes.toString("UTF-8"));
bytes.reset();
assertEquals(INPUT.length(), sstr.writeUnquotedUTF8(bytes));
assertEquals(INPUT, bytes.toString("UTF-8"));
byte[] buffer = new byte[100];
assertEquals(QUOTED.length(), sstr.appendQuotedUTF8(buffer, 3));
assertEquals(QUOTED, new String(buffer, 3, QUOTED.length()));
Arrays.fill(buffer, (byte) 0);
assertEquals(INPUT.length(), sstr.appendUnquotedUTF8(buffer, 5));
assertEquals(INPUT, new String(buffer, 5, INPUT.length()));
}