Example usage for com.fasterxml.jackson.core JsonGenerator flush

List of usage examples for com.fasterxml.jackson.core JsonGenerator flush

Introduction

In this page you can find the example usage for com.fasterxml.jackson.core JsonGenerator flush.

Prototype

@Override
public abstract void flush() throws IOException;

Source Link

Document

Method called to flush any buffered content to the underlying target (output stream, writer), and to flush the target itself as well.

Usage

From source file:com.cinnober.msgcodec.json.JsonValueHandlerTest.java

@Test
public void testFloat32EncodePosInfinity() throws IOException {
    StringWriter out = new StringWriter();
    JsonGenerator g = f.createGenerator(out);

    JsonValueHandler.FLOAT32.writeValue(Float.POSITIVE_INFINITY, g);
    g.flush();
    assertEquals("\"Infinity\"", out.toString());
}

From source file:com.cinnober.msgcodec.json.JsonValueHandlerTest.java

@Test
public void testFloat32EncodeNegInfinity() throws IOException {
    StringWriter out = new StringWriter();
    JsonGenerator g = f.createGenerator(out);

    JsonValueHandler.FLOAT32.writeValue(Float.NEGATIVE_INFINITY, g);
    g.flush();
    assertEquals("\"-Infinity\"", out.toString());
}

From source file:com.cinnober.msgcodec.json.JsonValueHandlerTest.java

@Test
public void testFloat64EncodePosInfinity() throws IOException {
    StringWriter out = new StringWriter();
    JsonGenerator g = f.createGenerator(out);

    JsonValueHandler.FLOAT64.writeValue(Double.POSITIVE_INFINITY, g);
    g.flush();
    assertEquals("\"Infinity\"", out.toString());
}

From source file:com.cinnober.msgcodec.json.JsonValueHandlerTest.java

@Test
public void testFloat64EncodeNegInfinity() throws IOException {
    StringWriter out = new StringWriter();
    JsonGenerator g = f.createGenerator(out);

    JsonValueHandler.FLOAT64.writeValue(Double.NEGATIVE_INFINITY, g);
    g.flush();
    assertEquals("\"-Infinity\"", out.toString());
}

From source file:org.dswarm.xsd2jsonschema.model.JSRoot.java

@Override
public void render(final JsonGenerator jgen) throws IOException {
    jgen.writeStartObject();//from  w w w .j  av a  2 s  .co m

    jgen.writeStringField("title", getName());
    jgen.writeStringField("type", getType());

    renderDescription(jgen);

    renderInternal(jgen);

    jgen.writeEndObject();

    jgen.flush();
    jgen.close();
}

From source file:org.seedstack.seed.core.internal.diagnostic.DefaultDiagnosticReporter.java

void writeDiagnosticReport(Map<String, Object> diagnosticInfo, OutputStream outputStream) throws IOException {
    JsonGenerator jsonGenerator = null;
    try {//from www  . j av a 2s  .  c  o  m
        jsonGenerator = JSON_FACTORY
                .createGenerator(new OutputStreamWriter(outputStream, Charset.forName("UTF-8").newEncoder()));
        jsonGenerator.setPrettyPrinter(DEFAULT_PRETTY_PRINTER);
        jsonGenerator.writeObject(diagnosticInfo);
        jsonGenerator.flush();
    } finally {
        if (jsonGenerator != null) {
            try {
                jsonGenerator.close();
            } catch (IOException e) {
                LOGGER.warn("Unable to close diagnostic stream", e);
            }
        }
    }
}

From source file:com.effektif.workflow.impl.json.JsonStreamMapper.java

public <T> void write(T bean, Writer writer) {
    try {//w ww.  j ava  2s  . co  m
        JsonGenerator jgen = new JsonFactory().createGenerator(writer);
        if (pretty) {
            jgen.setPrettyPrinter(new DefaultPrettyPrinter());
        }
        JsonStreamWriter jsonStreamWriter = new JsonStreamWriter(mappings, jgen);
        jsonStreamWriter.writeObject(bean);
        jgen.flush();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.attribyte.essem.ESReporter.java

static final void generateGauge(final JsonGenerator generator, final ReportProtos.EssemReport.Gauge gauge,
        final String application, final String host, final String instance, final long timestamp)
        throws IOException {

    generator.writeStartObject();//from   ww w  . ja  va  2s  . co m
    writeStringField(generator, Fields.APPLICATION_FIELD, application);
    writeStringField(generator, Fields.HOST_FIELD, host);
    writeStringField(generator, Fields.INSTANCE_FIELD, instance);
    writeStringField(generator, Fields.NAME_FIELD, gauge.getName().trim());
    if (gauge.hasValue()) {
        generator.writeNumberField(Fields.VALUE_FIELD, gauge.getValue());
    } else if (gauge.hasComment()) {
        generator.writeNumberField(Fields.VALUE_FIELD, 0.0);
        writeStringField(generator, Fields.COMMENT_FIELD, gauge.getComment());
    } else {
        generator.writeNullField(Fields.VALUE_FIELD);
    }

    generator.writeNumberField(Fields.TIMESTAMP_FIELD, timestamp);
    generator.writeEndObject();
    generator.flush();
}

From source file:com.cinnober.msgcodec.json.JsonCodec.java

@Override
public void encode(Object group, OutputStream out) throws IOException {
    if (group == null) {
        out.write(NULL_BYTES);//from   w  w  w .  jav  a 2  s. com
    } else {
        JsonFactory f = new JsonFactory();
        JsonGenerator g = f.createGenerator(out);
        dynamicGroupHandler.writeValue(group, g);
        g.flush();
    }
}

From source file:com.ibm.ws.lars.rest.FrontPage.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    resp.setContentType(MediaType.APPLICATION_JSON);
    resp.setCharacterEncoding(StandardCharsets.UTF_8.name());
    PrintWriter printWriter = resp.getWriter();

    List<AssetFilter> filters = new ArrayList<>();
    filters.add(new AssetFilter("state",
            Arrays.asList(new Condition[] { new Condition(Operation.EQUALS, "published") })));
    int assetCount = serviceLayer.countAllAssets(filters, null);

    JsonGenerator frontPageJsonGenerator = new JsonFactory().createGenerator(printWriter);
    frontPageJsonGenerator.setPrettyPrinter(new DefaultPrettyPrinter());

    frontPageJsonGenerator.writeStartObject();
    frontPageJsonGenerator.writeStringField("serverName", "LARS");
    frontPageJsonGenerator.writeNumberField("assetCount", assetCount);
    frontPageJsonGenerator.writeEndObject();

    frontPageJsonGenerator.flush();
    frontPageJsonGenerator.close();//from  w ww .j  a va 2 s. co  m
}