@Test public void testWrite() throws Exception { ByteArrayOutputStream bos = new ByteArrayOutputStream(); bw.write(objects, false, bos); JsonNode root = mapper.readTree(bos.toString("UTF-8")); assertThatObjectsAreWritten(root); }
public void write(Collection<?> objects, boolean allOrNothing, OutputStream out) { try { JsonGenerator jg = objectMapper.getFactory().createGenerator(out, JsonEncoding.UTF8); jg.writeStartObject(); if (allOrNothing) { jg.writeBooleanField("all_or_nothing", true); } jg.writeArrayFieldStart("docs"); for (Object o : objects) { jg.writeObject(o); } jg.writeEndArray(); jg.writeEndObject(); jg.flush(); jg.close(); } catch (Exception e) { throw Exceptions.propagate(e); } finally { IOUtils.closeQuietly(out); } }
BulkDocumentWriter { public void write(Collection<?> objects, boolean allOrNothing, OutputStream out) { try { JsonGenerator jg = objectMapper.getFactory().createGenerator(out, JsonEncoding.UTF8); jg.writeStartObject(); if (allOrNothing) { jg.writeBooleanField("all_or_nothing", true); } jg.writeArrayFieldStart("docs"); for (Object o : objects) { jg.writeObject(o); } jg.writeEndArray(); jg.writeEndObject(); jg.flush(); jg.close(); } catch (Exception e) { throw Exceptions.propagate(e); } finally { IOUtils.closeQuietly(out); } } }
BulkDocumentWriter { public void write(Collection<?> objects, boolean allOrNothing, OutputStream out) { try { JsonGenerator jg = objectMapper.getFactory().createGenerator(out, JsonEncoding.UTF8); jg.writeStartObject(); if (allOrNothing) { jg.writeBooleanField("all_or_nothing", true); } jg.writeArrayFieldStart("docs"); for (Object o : objects) { jg.writeObject(o); } jg.writeEndArray(); jg.writeEndObject(); jg.flush(); jg.close(); } catch (Exception e) { throw Exceptions.propagate(e); } finally { IOUtils.closeQuietly(out); } } BulkDocumentWriter(ObjectMapper om); }
BulkDocumentWriter { public void write(Collection<?> objects, boolean allOrNothing, OutputStream out) { try { JsonGenerator jg = objectMapper.getFactory().createGenerator(out, JsonEncoding.UTF8); jg.writeStartObject(); if (allOrNothing) { jg.writeBooleanField("all_or_nothing", true); } jg.writeArrayFieldStart("docs"); for (Object o : objects) { jg.writeObject(o); } jg.writeEndArray(); jg.writeEndObject(); jg.flush(); jg.close(); } catch (Exception e) { throw Exceptions.propagate(e); } finally { IOUtils.closeQuietly(out); } } BulkDocumentWriter(ObjectMapper om); void write(Collection<?> objects, boolean allOrNothing, OutputStream out); InputStream createInputStreamWrapper(boolean allOrNothing, InputStream in); }
BulkDocumentWriter { public void write(Collection<?> objects, boolean allOrNothing, OutputStream out) { try { JsonGenerator jg = objectMapper.getFactory().createGenerator(out, JsonEncoding.UTF8); jg.writeStartObject(); if (allOrNothing) { jg.writeBooleanField("all_or_nothing", true); } jg.writeArrayFieldStart("docs"); for (Object o : objects) { jg.writeObject(o); } jg.writeEndArray(); jg.writeEndObject(); jg.flush(); jg.close(); } catch (Exception e) { throw Exceptions.propagate(e); } finally { IOUtils.closeQuietly(out); } } BulkDocumentWriter(ObjectMapper om); void write(Collection<?> objects, boolean allOrNothing, OutputStream out); InputStream createInputStreamWrapper(boolean allOrNothing, InputStream in);  }