@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); }
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 { 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 { 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); }
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); }
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);  }