@Test void convertsMultiDocList() { JsonObject i1 = JsonObject.create().put("hello", "world"); String i2 = "What?"; boolean i3 = false; byte[] result = MutateInUtil.convertDocsToBytes(Arrays.asList(i1, i2, i3), JSON_SERIALIZER); assertArrayEquals("{\"hello\":\"world\"},\"What?\",false".getBytes(StandardCharsets.UTF_8), result); }
static byte[] convertDocsToBytes(final List<?> docs, final JsonSerializer serializer) { if (docs.size() == 1) { return serializer.serialize(docs.get(0)); } else { final ByteBuf bytes = UnpooledByteBufAllocator.DEFAULT.heapBuffer(); try { final Iterator<?> it = docs.iterator(); while (it.hasNext()) { Object d = it.next(); bytes.writeBytes(serializer.serialize(d)); if (it.hasNext()) { bytes.writeByte(','); } } return ByteBufUtil.getBytes(bytes); } finally { bytes.release(); } } }
MutateInUtil { static byte[] convertDocsToBytes(final List<?> docs, final JsonSerializer serializer) { if (docs.size() == 1) { return serializer.serialize(docs.get(0)); } else { final ByteBuf bytes = UnpooledByteBufAllocator.DEFAULT.heapBuffer(); try { final Iterator<?> it = docs.iterator(); while (it.hasNext()) { Object d = it.next(); bytes.writeBytes(serializer.serialize(d)); if (it.hasNext()) { bytes.writeByte(','); } } return ByteBufUtil.getBytes(bytes); } finally { bytes.release(); } } } }
MutateInUtil { static byte[] convertDocsToBytes(final List<?> docs, final JsonSerializer serializer) { if (docs.size() == 1) { return serializer.serialize(docs.get(0)); } else { final ByteBuf bytes = UnpooledByteBufAllocator.DEFAULT.heapBuffer(); try { final Iterator<?> it = docs.iterator(); while (it.hasNext()) { Object d = it.next(); bytes.writeBytes(serializer.serialize(d)); if (it.hasNext()) { bytes.writeByte(','); } } return ByteBufUtil.getBytes(bytes); } finally { bytes.release(); } } } private  MutateInUtil(); }
MutateInUtil { static byte[] convertDocsToBytes(final List<?> docs, final JsonSerializer serializer) { if (docs.size() == 1) { return serializer.serialize(docs.get(0)); } else { final ByteBuf bytes = UnpooledByteBufAllocator.DEFAULT.heapBuffer(); try { final Iterator<?> it = docs.iterator(); while (it.hasNext()) { Object d = it.next(); bytes.writeBytes(serializer.serialize(d)); if (it.hasNext()) { bytes.writeByte(','); } } return ByteBufUtil.getBytes(bytes); } finally { bytes.release(); } } } private  MutateInUtil();  }
MutateInUtil { static byte[] convertDocsToBytes(final List<?> docs, final JsonSerializer serializer) { if (docs.size() == 1) { return serializer.serialize(docs.get(0)); } else { final ByteBuf bytes = UnpooledByteBufAllocator.DEFAULT.heapBuffer(); try { final Iterator<?> it = docs.iterator(); while (it.hasNext()) { Object d = it.next(); bytes.writeBytes(serializer.serialize(d)); if (it.hasNext()) { bytes.writeByte(','); } } return ByteBufUtil.getBytes(bytes); } finally { bytes.release(); } } } private  MutateInUtil();   }