json.writeMapEnd();
json.close();
// Compare this against our expectations
final DataInputStream in = new DataInputStream(new ByteArrayInputStream(baos.toByteArray()));
final Reader reader = new Utf8InputStreamReader(in);
final char[] chars = new char[88];
assertNextStringFromReader(reader, "{\"header\":[", chars);
for (int i = 0; i < columns.length; i++) {
assertNextStringFromReader(reader, "\"" + columns[i] + "\"", chars);
if (i < columns.length - 1) {
assertEquals(',', (char) reader.read());
}
}
assertNextStringFromReader(reader, "],\"rows\":[[\"", chars);
assertNextStringFromReader(reader, testChars, chars);
assertNextStringFromReader(reader, "\",\"", chars);
assertNextStringFromReader(reader, id1, chars);
assertNextStringFromReader(reader, "\",`", chars);
assertEquals(37, in.readLong());
for (int i = 0; i < 37; i++) {
assertEquals(i, in.read());
}
assertNextStringFromReader(reader, "`],[\"", chars);
assertNextStringFromReader(reader, uuid, chars);
assertNextStringFromReader(reader, "\",\"", chars);
assertNextStringFromReader(reader, id2, chars);
assertNextStringFromReader(reader, "\",`", chars);
assertEquals(7, in.readLong());
for (int i = 0; i < 7; i++) {
assertEquals(255 - i, in.read());
}
assertNextStringFromReader(reader, "`]]}", chars);
assertEquals(-1, reader.read());
assertEquals(-1, in.read());
}