### Question:
BulkDocumentWriter { public InputStream createInputStreamWrapper(boolean allOrNothing, InputStream in) { List<InputStream> seq = new ArrayList<InputStream>(3); try { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); JsonGenerator jg = objectMapper.getFactory().createGenerator(byteArrayOutputStream, JsonEncoding.UTF8); jg.writeStartObject(); if (allOrNothing) { jg.writeBooleanField("all_or_nothing", true); } jg.writeFieldName("docs"); jg.writeRaw(':'); jg.flush(); seq.add(new ByteArrayInputStream(byteArrayOutputStream.toByteArray())); seq.add(in); byteArrayOutputStream.reset(); jg.writeEndObject(); jg.flush(); jg.close(); seq.add(new ByteArrayInputStream(byteArrayOutputStream.toByteArray())); } catch (Exception e) { throw Exceptions.propagate(e); } return new SequenceInputStream(Collections.enumeration(seq)); } BulkDocumentWriter(ObjectMapper om); void write(Collection<?> objects, boolean allOrNothing, OutputStream out); InputStream createInputStreamWrapper(boolean allOrNothing, InputStream in);  }### Answer:
@Test public void testCreateInputStreamWrapper() throws Exception { ByteArrayInputStream bis = new ByteArrayInputStream("[{\"_id\":\"0\",\"key\":\"key_value\",\"value\":\"doc_value0\"},{\"_id\":\"1\",\"key\":\"key_value\",\"value\":\"doc_value1\"},{\"_id\":\"2\",\"key\":\"key_value\",\"value\":\"doc_value2\"}]".getBytes("UTF-8")); InputStream inputStream = bw.createInputStreamWrapper(true, bis); JsonNode root = mapper.readTree(inputStream); assertThatObjectsAreWritten(root); }
@Test public void testInputStreamBulkEntityIsEquivalentToInputStreamWrapper() throws Exception { String originalDocumentContent = "[{\"_id\":\"0\",\"key\":\"key_value\",\"value\":\"doc_value0\"},{\"_id\":\"1\",\"key\":\"key_value\",\"value\":\"doc_value1\"},{\"_id\":\"2\",\"key\":\"key_value\",\"value\":\"doc_value2\"}]"; InputStream inputStream = bw.createInputStreamWrapper(true, new ByteArrayInputStream(originalDocumentContent.getBytes("UTF-8"))); ByteArrayOutputStream resultUsingInputStreamBulkEntity = new ByteArrayOutputStream(); InputStreamBulkEntity inputStreamBulkEntity = new InputStreamBulkEntity(new ByteArrayInputStream(originalDocumentContent.getBytes("UTF-8")), true); inputStreamBulkEntity.writeTo(resultUsingInputStreamBulkEntity); InputStream inputStreamUsingInputStreamBulkEntity = new ByteArrayInputStream(resultUsingInputStreamBulkEntity.toByteArray()); assertEquals(IOUtils.toString(inputStream), IOUtils.toString(inputStreamUsingInputStreamBulkEntity)); assertTrue(IOUtils.contentEquals(inputStream, inputStreamUsingInputStreamBulkEntity)); }