}
private InputStream wrapInJson(final List<DebugInfo> parts) throws IOException {
CircleStreamBuffer csb = new CircleStreamBuffer();
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(csb.getOutputStream(), "UTF-8"));
JsonStreamWriter jsonStreamWriter = new JsonStreamWriter(writer);
jsonStreamWriter.beginObject();
jsonStreamWriter.name(parts.get(0).getName().toLowerCase(Locale.ROOT));
parts.get(0).appendJson(jsonStreamWriter);
jsonStreamWriter.separator();
jsonStreamWriter.name(parts.get(1).getName().toLowerCase(Locale.ROOT));
parts.get(1).appendJson(jsonStreamWriter);
if (parts.size() > 2) {
jsonStreamWriter.separator();
jsonStreamWriter.name("server")
.beginObject();
}
boolean first = true;
for (final DebugInfo part : parts.subList(2, parts.size())) {
if (!first) {
jsonStreamWriter.separator();
}
first = false;
jsonStreamWriter.name(part.getName().toLowerCase(Locale.ROOT));
part.appendJson(jsonStreamWriter);
}
if (parts.size() > 2) {
jsonStreamWriter.endObject();
}
jsonStreamWriter.endObject();
writer.flush();
csb.closeWrite();
return csb.getInputStream();
}