List of usage examples for com.fasterxml.jackson.core JsonGenerator flush
@Override public abstract void flush() throws IOException;
From source file:com.attribyte.essem.es.QueryComponent.java
/** * Generate to an output stream./*from w w w . java 2 s . c om*/ * @param os The output stream. * @throws IOException on write error. */ public void generate(final OutputStream os) throws IOException { JsonGenerator generator = jsonFactory.createGenerator(os); generate(generator); generator.flush(); }
From source file:org.axway.grapes.server.webapp.views.serialization.LicenseSerializer.java
@Override public void serialize(final LicenseView licenseView, final JsonGenerator json, final SerializerProvider serializer) throws IOException { json.writeObject(licenseView.getLicense()); json.flush(); }
From source file:com.attribyte.essem.es.QueryComponent.java
/** * Write the query as a JSON strung.//from w w w . ja va 2s .c om * @return The JSON string. * @throws IOException on write error. */ public String toJSON() throws IOException { StringWriter writer = new StringWriter(); JsonGenerator generator = jsonFactory.createGenerator(writer); generate(generator); generator.flush(); return writer.toString(); }
From source file:org.apache.olingo.server.core.debug.AbstractDebugTabTest.java
protected String createJson(DebugTab requestTab) throws IOException { CircleStreamBuffer csb = new CircleStreamBuffer(); JsonGenerator gen = new JsonFactory().createGenerator(csb.getOutputStream(), JsonEncoding.UTF8); requestTab.appendJson(gen);/*from ww w . j a v a 2s .c o m*/ gen.flush(); gen.close(); csb.closeWrite(); return IOUtils.toString(csb.getInputStream()); }
From source file:com.attribyte.essem.es.QueryComponent.java
/** * Generate pretty JSON to an output stream. * @param os The output stream.//from ww w . ja v a 2 s . co m * @throws IOException on write error. */ public void generatePretty(final OutputStream os) throws IOException { JsonGenerator generator = jsonFactory.createGenerator(os).useDefaultPrettyPrinter(); generate(generator); generator.flush(); }
From source file:com.attribyte.essem.es.QueryComponent.java
/** * Writes the query as a "pretty" JSON string. * @return The JSON string.//from w w w . j a va 2 s. c o m * @throws IOException on write error. */ public String toPrettyJSON() throws IOException { StringWriter writer = new StringWriter(); JsonGenerator generator = jsonFactory.createGenerator(writer).useDefaultPrettyPrinter(); generate(generator); generator.flush(); return writer.toString(); }
From source file:org.axway.grapes.server.webapp.views.serialization.LicenseLisSerializer.java
@Override public void serialize(final LicenseListView licenseList, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider) throws IOException, JsonProcessingException { jsonGenerator.writeObject(licenseList.getLicenses()); jsonGenerator.flush(); }
From source file:org.springframework.cloud.stream.metrics.config.MetricJsonSerializerTests.java
@Test public void validateAlwaysGMTDateAndFormat() throws Exception { Date date = new Date(1493060197188L); // Mon Apr 24 14:56:37 EDT 2017 Metric<Number> metric = new Metric<Number>("Hello", 123, date); JsonFactory factory = new JsonFactory(); StringWriter writer = new StringWriter(); JsonGenerator jsonGenerator = factory.createGenerator(writer); Serializer ser = new Serializer(); ser.serialize(metric, jsonGenerator, null); jsonGenerator.flush(); JSONObject json = new JSONObject(writer.toString()); String serializedTimestamp = json.getString("timestamp"); assertEquals("2017-04-24T18:56:37.188Z", serializedTimestamp); }
From source file:com.predic8.membrane.core.interceptor.rest.RESTInterceptor.java
protected Response json(JSONContent content) throws Exception { StringWriter jsonTxt = new StringWriter(); JsonGenerator gen = jsonFactory.createGenerator(jsonTxt); content.write(gen);/*w w w. ja v a 2 s.com*/ gen.flush(); return Response.ok().header(Header.CONTENT_TYPE, MimeType.APPLICATION_JSON_UTF8).body(jsonTxt.toString()) .build(); }
From source file:com.netflix.spectator.tdigest.TDigestWriter.java
/** * Write a list of measurements to some underlying storage. *//*from ww w .j a v a 2 s . co m*/ void write(List<TDigestMeasurement> measurements) throws IOException { JsonGenerator gen = json.newGenerator(out); gen.writeStartArray(); gen.flush(); int pos = buf.position(); for (TDigestMeasurement m : measurements) { json.encode(commonTags, m, gen); gen.flush(); if (out.overflow()) { // Ignore the last entry written to the buffer out.setPosition(pos); gen.writeEndArray(); gen.close(); write(buf); // Reuse the buffer and write the current entry out.reset(); gen = json.newGenerator(out); gen.writeStartArray(); json.encode(commonTags, m, gen); gen.flush(); // If a single entry is too big, then drop it if (out.overflow()) { LOGGER.warn("dropping measurement {}, serialized size exceeds the buffer cap", m.id()); out.reset(); gen = json.newGenerator(out); gen.writeStartArray(); gen.flush(); } pos = buf.position(); } else if (buf.remaining() < MIN_FREE) { // Not enough free-space, go ahead and write gen.writeEndArray(); gen.close(); write(buf); // Reuse the buffer out.reset(); gen = json.newGenerator(out); gen.writeStartArray(); gen.flush(); pos = buf.position(); } else { pos = buf.position(); } } // Write any data that is still in the buffer if (buf.position() > 1) { gen.writeEndArray(); gen.close(); write(buf); } }