Java Code Examples for org.codehaus.jackson.JsonGenerator#writeNumberField()

The following examples show how to use org.codehaus.jackson.JsonGenerator#writeNumberField() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DetectedLanguageWriter.java    From stanbol-freeling with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void writeTo(Collection<Language> detected, Class<?> type, Type genericType, Annotation[] annotations,
        MediaType mediaType, MultivaluedMap<String,Object> httpHeaders, OutputStream entityStream)
        throws IOException, WebApplicationException {
    JsonGenerator jg = getJsonFactory().createJsonGenerator(entityStream);
    jg.writeStartArray();
    for(Language lang : detected){
        jg.writeStartObject();
        jg.writeStringField("lang", lang.getLang());
        if(lang.getProb() > 0){
            jg.writeNumberField("prob", lang.getProb());
        }
        jg.writeEndObject();
    }
    jg.writeEndArray();
    jg.close();
}
 
Example 2
Source File: Log4Json.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Build a JSON entry from the parameters. This is public for testing.
 *
 * @param writer destination
 * @param loggerName logger name
 * @param timeStamp time_t value
 * @param level level string
 * @param threadName name of the thread
 * @param message rendered message
 * @param ti nullable thrown information
 * @return the writer
 * @throws IOException on any problem
 */
public Writer toJson(final Writer writer,
                     final String loggerName,
                     final long timeStamp,
                     final String level,
                     final String threadName,
                     final String message,
                     final ThrowableInformation ti) throws IOException {
  JsonGenerator json = factory.createJsonGenerator(writer);
  json.writeStartObject();
  json.writeStringField(NAME, loggerName);
  json.writeNumberField(TIME, timeStamp);
  Date date = new Date(timeStamp);
  json.writeStringField(DATE, dateFormat.format(date));
  json.writeStringField(LEVEL, level);
  json.writeStringField(THREAD, threadName);
  json.writeStringField(MESSAGE, message);
  if (ti != null) {
    //there is some throwable info, but if the log event has been sent over the wire,
    //there may not be a throwable inside it, just a summary.
    Throwable thrown = ti.getThrowable();
    String eclass = (thrown != null) ?
        thrown.getClass().getName()
        : "";
    json.writeStringField(EXCEPTION_CLASS, eclass);
    String[] stackTrace = ti.getThrowableStrRep();
    json.writeArrayFieldStart(STACK);
    for (String row : stackTrace) {
      json.writeString(row);
    }
    json.writeEndArray();
  }
  json.writeEndObject();
  json.flush();
  json.close();
  return writer;
}
 
Example 3
Source File: Log4Json.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Build a JSON entry from the parameters. This is public for testing.
 *
 * @param writer destination
 * @param loggerName logger name
 * @param timeStamp time_t value
 * @param level level string
 * @param threadName name of the thread
 * @param message rendered message
 * @param ti nullable thrown information
 * @return the writer
 * @throws IOException on any problem
 */
public Writer toJson(final Writer writer,
                     final String loggerName,
                     final long timeStamp,
                     final String level,
                     final String threadName,
                     final String message,
                     final ThrowableInformation ti) throws IOException {
  JsonGenerator json = factory.createJsonGenerator(writer);
  json.writeStartObject();
  json.writeStringField(NAME, loggerName);
  json.writeNumberField(TIME, timeStamp);
  Date date = new Date(timeStamp);
  json.writeStringField(DATE, dateFormat.format(date));
  json.writeStringField(LEVEL, level);
  json.writeStringField(THREAD, threadName);
  json.writeStringField(MESSAGE, message);
  if (ti != null) {
    //there is some throwable info, but if the log event has been sent over the wire,
    //there may not be a throwable inside it, just a summary.
    Throwable thrown = ti.getThrowable();
    String eclass = (thrown != null) ?
        thrown.getClass().getName()
        : "";
    json.writeStringField(EXCEPTION_CLASS, eclass);
    String[] stackTrace = ti.getThrowableStrRep();
    json.writeArrayFieldStart(STACK);
    for (String row : stackTrace) {
      json.writeString(row);
    }
    json.writeEndArray();
  }
  json.writeEndObject();
  json.flush();
  json.close();
  return writer;
}
 
Example 4
Source File: JsonMapper.java    From ReactiveLab with Apache License 2.0 5 votes vote down vote up
static String toJson(HystrixThreadPoolMetrics threadPoolMetrics) throws IOException {
    HystrixThreadPoolKey key = threadPoolMetrics.getThreadPoolKey();

    StringWriter jsonString = new StringWriter();
    JsonGenerator json = jsonFactory.createJsonGenerator(jsonString);
    json.writeStartObject();

    json.writeStringField("type", "HystrixThreadPool");
    json.writeStringField("name", key.name());
    json.writeNumberField("currentTime", System.currentTimeMillis());

    json.writeNumberField("currentActiveCount", threadPoolMetrics.getCurrentActiveCount().intValue());
    json.writeNumberField("currentCompletedTaskCount", threadPoolMetrics.getCurrentCompletedTaskCount().longValue());
    json.writeNumberField("currentCorePoolSize", threadPoolMetrics.getCurrentCorePoolSize().intValue());
    json.writeNumberField("currentLargestPoolSize", threadPoolMetrics.getCurrentLargestPoolSize().intValue());
    json.writeNumberField("currentMaximumPoolSize", threadPoolMetrics.getCurrentMaximumPoolSize().intValue());
    json.writeNumberField("currentPoolSize", threadPoolMetrics.getCurrentPoolSize().intValue());
    json.writeNumberField("currentQueueSize", threadPoolMetrics.getCurrentQueueSize().intValue());
    json.writeNumberField("currentTaskCount", threadPoolMetrics.getCurrentTaskCount().longValue());
    json.writeNumberField("rollingCountThreadsExecuted", threadPoolMetrics.getRollingCountThreadsExecuted());
    json.writeNumberField("rollingMaxActiveThreads", threadPoolMetrics.getRollingMaxActiveThreads());

    json.writeNumberField("propertyValue_queueSizeRejectionThreshold", threadPoolMetrics.getProperties().queueSizeRejectionThreshold().get());
    json.writeNumberField("propertyValue_metricsRollingStatisticalWindowInMilliseconds", threadPoolMetrics.getProperties().metricsRollingStatisticalWindowInMilliseconds().get());

    json.writeNumberField("reportingHosts", 1); // this will get summed across all instances in a cluster

    json.writeEndObject();
    json.close();

    return jsonString.getBuffer().toString();
}
 
Example 5
Source File: NameNodeLoader.java    From NNAnalytics with Apache License 2.0 4 votes vote down vote up
/**
 * Sends the loading status as JSON to the parameter HTTP response. Copied from NameNode.
 *
 * @param resp the HTTP response
 * @throws IOException error in fetching loading status
 */
public void sendLoadingStatus(HttpServletResponse resp) throws IOException {
  String count = "count";
  String elapsedTime = "elapsedTime";
  String file = "file";
  String name = "name";
  String desc = "desc";
  String percentComplete = "percentComplete";
  String phases = "phases";
  String size = "size";
  String status = "status";
  String steps = "steps";
  String total = "total";

  StartupProgressView view = NameNode.getStartupProgress().createView();
  JsonGenerator json =
      new JsonFactory().createJsonGenerator(resp.getWriter()).useDefaultPrettyPrinter();

  try {
    json.writeStartObject();
    json.writeNumberField(elapsedTime, view.getElapsedTime());
    json.writeNumberField(percentComplete, view.getPercentComplete());
    json.writeArrayFieldStart(phases);

    for (Phase phase : view.getPhases()) {
      json.writeStartObject();
      json.writeStringField(name, phase.getName());
      json.writeStringField(desc, phase.getDescription());
      json.writeStringField(status, view.getStatus(phase).toString());
      json.writeNumberField(percentComplete, view.getPercentComplete(phase));
      json.writeNumberField(elapsedTime, view.getElapsedTime(phase));
      writeStringFieldIfNotNull(json, file, view.getFile(phase));
      writeNumberFieldIfDefined(json, size, view.getSize(phase));
      json.writeArrayFieldStart(steps);

      for (Step step : view.getSteps(phase)) {
        json.writeStartObject();
        StepType stepType = step.getType();
        if (stepType != null) {
          json.writeStringField(name, stepType.getName());
          json.writeStringField(desc, stepType.getDescription());
        }
        json.writeNumberField(count, view.getCount(phase, step));
        writeStringFieldIfNotNull(json, file, step.getFile());
        writeNumberFieldIfDefined(json, size, step.getSize());
        json.writeNumberField(total, view.getTotal(phase, step));
        json.writeNumberField(percentComplete, view.getPercentComplete(phase, step));
        json.writeNumberField(elapsedTime, view.getElapsedTime(phase, step));
        json.writeEndObject();
      }

      json.writeEndArray();
      json.writeEndObject();
    }

    json.writeEndArray();
    json.writeEndObject();
  } finally {
    IOUtils.closeStream(json);
  }
}
 
Example 6
Source File: NameNodeLoader.java    From NNAnalytics with Apache License 2.0 4 votes vote down vote up
private void writeNumberFieldIfDefined(JsonGenerator json, String key, Long value)
    throws IOException {
  if (value != Long.MIN_VALUE) {
    json.writeNumberField(key, value);
  }
}
 
Example 7
Source File: StartupProgressServlet.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
    throws IOException {
  resp.setContentType("application/json; charset=UTF-8");
  StartupProgress prog = NameNodeHttpServer.getStartupProgressFromContext(
    getServletContext());
  StartupProgressView view = prog.createView();
  JsonGenerator json = new JsonFactory().createJsonGenerator(resp.getWriter());
  try {
    json.writeStartObject();
    json.writeNumberField(ELAPSED_TIME, view.getElapsedTime());
    json.writeNumberField(PERCENT_COMPLETE, view.getPercentComplete());
    json.writeArrayFieldStart(PHASES);

    for (Phase phase: view.getPhases()) {
      json.writeStartObject();
      json.writeStringField(NAME, phase.getName());
      json.writeStringField(DESC, phase.getDescription());
      json.writeStringField(STATUS, view.getStatus(phase).toString());
      json.writeNumberField(PERCENT_COMPLETE, view.getPercentComplete(phase));
      json.writeNumberField(ELAPSED_TIME, view.getElapsedTime(phase));
      writeStringFieldIfNotNull(json, FILE, view.getFile(phase));
      writeNumberFieldIfDefined(json, SIZE, view.getSize(phase));
      json.writeArrayFieldStart(STEPS);

      for (Step step: view.getSteps(phase)) {
        json.writeStartObject();
        StepType type = step.getType();
        if (type != null) {
          json.writeStringField(NAME, type.getName());
          json.writeStringField(DESC, type.getDescription());
        }
        json.writeNumberField(COUNT, view.getCount(phase, step));
        writeStringFieldIfNotNull(json, FILE, step.getFile());
        writeNumberFieldIfDefined(json, SIZE, step.getSize());
        json.writeNumberField(TOTAL, view.getTotal(phase, step));
        json.writeNumberField(PERCENT_COMPLETE, view.getPercentComplete(phase,
          step));
        json.writeNumberField(ELAPSED_TIME, view.getElapsedTime(phase, step));
        json.writeEndObject();
      }

      json.writeEndArray();
      json.writeEndObject();
    }

    json.writeEndArray();
    json.writeEndObject();
  } finally {
    IOUtils.cleanup(LOG, json);
  }
}
 
Example 8
Source File: StartupProgressServlet.java    From big-c with Apache License 2.0 4 votes vote down vote up
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
    throws IOException {
  resp.setContentType("application/json; charset=UTF-8");
  StartupProgress prog = NameNodeHttpServer.getStartupProgressFromContext(
    getServletContext());
  StartupProgressView view = prog.createView();
  JsonGenerator json = new JsonFactory().createJsonGenerator(resp.getWriter());
  try {
    json.writeStartObject();
    json.writeNumberField(ELAPSED_TIME, view.getElapsedTime());
    json.writeNumberField(PERCENT_COMPLETE, view.getPercentComplete());
    json.writeArrayFieldStart(PHASES);

    for (Phase phase: view.getPhases()) {
      json.writeStartObject();
      json.writeStringField(NAME, phase.getName());
      json.writeStringField(DESC, phase.getDescription());
      json.writeStringField(STATUS, view.getStatus(phase).toString());
      json.writeNumberField(PERCENT_COMPLETE, view.getPercentComplete(phase));
      json.writeNumberField(ELAPSED_TIME, view.getElapsedTime(phase));
      writeStringFieldIfNotNull(json, FILE, view.getFile(phase));
      writeNumberFieldIfDefined(json, SIZE, view.getSize(phase));
      json.writeArrayFieldStart(STEPS);

      for (Step step: view.getSteps(phase)) {
        json.writeStartObject();
        StepType type = step.getType();
        if (type != null) {
          json.writeStringField(NAME, type.getName());
          json.writeStringField(DESC, type.getDescription());
        }
        json.writeNumberField(COUNT, view.getCount(phase, step));
        writeStringFieldIfNotNull(json, FILE, step.getFile());
        writeNumberFieldIfDefined(json, SIZE, step.getSize());
        json.writeNumberField(TOTAL, view.getTotal(phase, step));
        json.writeNumberField(PERCENT_COMPLETE, view.getPercentComplete(phase,
          step));
        json.writeNumberField(ELAPSED_TIME, view.getElapsedTime(phase, step));
        json.writeEndObject();
      }

      json.writeEndArray();
      json.writeEndObject();
    }

    json.writeEndArray();
    json.writeEndObject();
  } finally {
    IOUtils.cleanup(LOG, json);
  }
}
 
Example 9
Source File: JsonMapper.java    From ReactiveLab with Apache License 2.0 4 votes vote down vote up
static String toJson(Metrics commandMetrics) throws IOException {
    StringWriter jsonString = new StringWriter();
    JsonGenerator json = jsonFactory.createJsonGenerator(jsonString);

    json.writeStartObject();
    json.writeStringField("type", "HystrixCommand"); // act as this as we are hijacking Hystrix for the dashboard
    json.writeStringField("name", commandMetrics.getName());
    json.writeStringField("group", "");
    json.writeNumberField("currentTime", System.currentTimeMillis());

    json.writeBooleanField("isCircuitBreakerOpen", false);

    long errors = commandMetrics.getRollingNumber().getRollingSum(Metrics.EventType.FAILURE);
    long success = commandMetrics.getRollingNumber().getRollingSum(Metrics.EventType.SUCCESS);
    long requests = success + errors;
    int errorPercentage = (int) ((double) errors / requests * 100);

    json.writeNumberField("errorPercentage", errorPercentage);
    json.writeNumberField("errorCount", errors);
    json.writeNumberField("requestCount", requests);

    // rolling counters
    json.writeNumberField("rollingCountCollapsedRequests", 0);
    json.writeNumberField("rollingCountExceptionsThrown", commandMetrics.getRollingNumber().getRollingSum(Metrics.EventType.EXCEPTION_THROWN));
    json.writeNumberField("rollingCountFailure", errors);
    json.writeNumberField("rollingCountFallbackFailure", 0);
    json.writeNumberField("rollingCountFallbackRejection", 0);
    json.writeNumberField("rollingCountFallbackSuccess", 0);
    json.writeNumberField("rollingCountResponsesFromCache", 0);
    json.writeNumberField("rollingCountSemaphoreRejected", 0);
    json.writeNumberField("rollingCountShortCircuited", 0);
    json.writeNumberField("rollingCountSuccess", success);
    json.writeNumberField("rollingCountThreadPoolRejected", 0);
    json.writeNumberField("rollingCountTimeout", 0);

    json.writeNumberField("currentConcurrentExecutionCount", commandMetrics.getRollingNumber().getRollingMaxValue(Metrics.EventType.CONCURRENCY_MAX_ACTIVE));

    // latency percentiles
    json.writeNumberField("latencyExecute_mean", commandMetrics.getRollingPercentile().getMean());
    json.writeObjectFieldStart("latencyExecute");
    json.writeNumberField("0", commandMetrics.getRollingPercentile().getPercentile(0));
    json.writeNumberField("25", commandMetrics.getRollingPercentile().getPercentile(25));
    json.writeNumberField("50", commandMetrics.getRollingPercentile().getPercentile(50));
    json.writeNumberField("75", commandMetrics.getRollingPercentile().getPercentile(75));
    json.writeNumberField("90", commandMetrics.getRollingPercentile().getPercentile(90));
    json.writeNumberField("95", commandMetrics.getRollingPercentile().getPercentile(95));
    json.writeNumberField("99", commandMetrics.getRollingPercentile().getPercentile(99));
    json.writeNumberField("99.5", commandMetrics.getRollingPercentile().getPercentile(99.5));
    json.writeNumberField("100", commandMetrics.getRollingPercentile().getPercentile(100));
    json.writeEndObject();

    json.writeNumberField("latencyTotal_mean", commandMetrics.getRollingPercentile().getMean());
    json.writeObjectFieldStart("latencyTotal");
    json.writeNumberField("0", commandMetrics.getRollingPercentile().getPercentile(0));
    json.writeNumberField("25", commandMetrics.getRollingPercentile().getPercentile(25));
    json.writeNumberField("50", commandMetrics.getRollingPercentile().getPercentile(50));
    json.writeNumberField("75", commandMetrics.getRollingPercentile().getPercentile(75));
    json.writeNumberField("90", commandMetrics.getRollingPercentile().getPercentile(90));
    json.writeNumberField("95", commandMetrics.getRollingPercentile().getPercentile(95));
    json.writeNumberField("99", commandMetrics.getRollingPercentile().getPercentile(99));
    json.writeNumberField("99.5", commandMetrics.getRollingPercentile().getPercentile(99.5));
    json.writeNumberField("100", commandMetrics.getRollingPercentile().getPercentile(100));
    json.writeEndObject();
    
    json.writeNumberField("propertyValue_circuitBreakerRequestVolumeThreshold", 0);
    json.writeNumberField("propertyValue_circuitBreakerSleepWindowInMilliseconds", 0);
    json.writeNumberField("propertyValue_circuitBreakerErrorThresholdPercentage", 0);
    json.writeBooleanField("propertyValue_circuitBreakerForceOpen", false);
    json.writeBooleanField("propertyValue_circuitBreakerForceClosed", false);
    json.writeBooleanField("propertyValue_circuitBreakerEnabled", false);

    json.writeStringField("propertyValue_executionIsolationStrategy", "");
    json.writeNumberField("propertyValue_executionIsolationThreadTimeoutInMilliseconds", 0);
    json.writeBooleanField("propertyValue_executionIsolationThreadInterruptOnTimeout", false);
    json.writeStringField("propertyValue_executionIsolationThreadPoolKeyOverride", "");
    json.writeNumberField("propertyValue_executionIsolationSemaphoreMaxConcurrentRequests", 0);
    json.writeNumberField("propertyValue_fallbackIsolationSemaphoreMaxConcurrentRequests", 0);

    json.writeNumberField("propertyValue_metricsRollingStatisticalWindowInMilliseconds", 10000);

    json.writeBooleanField("propertyValue_requestCacheEnabled", false);
    json.writeBooleanField("propertyValue_requestLogEnabled", false);

    
    json.writeNumberField("reportingHosts", 1); // this will get summed across all instances in a cluster

    json.writeEndObject();
    json.close();

    return jsonString.getBuffer().toString();
}
 
Example 10
Source File: ResponseBuilder.java    From ReactiveLab with Apache License 2.0 4 votes vote down vote up
private static void generateResponse(BackendResponse responseA, BackendResponse responseB, BackendResponse responseC, BackendResponse responseD, BackendResponse responseE, JsonGenerator jsonGenerator) throws IOException, JsonGenerationException {
    jsonGenerator.writeStartObject();
    // multiplication of C, D, E responseKey
    jsonGenerator.writeNumberField("responseKey", responseC.getResponseKey() + responseD.getResponseKey() +
            responseE.getResponseKey());

    // delay values of each response
    jsonGenerator.writeArrayFieldStart("delay");
    writeTuple(jsonGenerator, "a", responseA.getDelay());
    writeTuple(jsonGenerator, "b", responseB.getDelay());
    writeTuple(jsonGenerator, "c", responseC.getDelay());
    writeTuple(jsonGenerator, "d", responseD.getDelay());
    writeTuple(jsonGenerator, "e", responseE.getDelay());
    jsonGenerator.writeEndArray();

    // itemSize values of each response
    jsonGenerator.writeArrayFieldStart("itemSize");
    writeTuple(jsonGenerator, "a", responseA.getItemSize());
    writeTuple(jsonGenerator, "b", responseB.getItemSize());
    writeTuple(jsonGenerator, "c", responseC.getItemSize());
    writeTuple(jsonGenerator, "d", responseD.getItemSize());
    writeTuple(jsonGenerator, "e", responseE.getItemSize());
    jsonGenerator.writeEndArray();

    // numItems values of each response
    jsonGenerator.writeArrayFieldStart("numItems");
    writeTuple(jsonGenerator, "a", responseA.getNumItems());
    writeTuple(jsonGenerator, "b", responseB.getNumItems());
    writeTuple(jsonGenerator, "c", responseC.getNumItems());
    writeTuple(jsonGenerator, "d", responseD.getNumItems());
    writeTuple(jsonGenerator, "e", responseE.getNumItems());
    jsonGenerator.writeEndArray();

    // all items from responses
    jsonGenerator.writeArrayFieldStart("items");
    addItemsFromResponse(jsonGenerator, responseA);
    addItemsFromResponse(jsonGenerator, responseB);
    addItemsFromResponse(jsonGenerator, responseC);
    addItemsFromResponse(jsonGenerator, responseD);
    addItemsFromResponse(jsonGenerator, responseE);
    jsonGenerator.writeEndArray();

    jsonGenerator.writeEndObject();
}
 
Example 11
Source File: ResponseBuilder.java    From ReactiveLab with Apache License 2.0 4 votes vote down vote up
private static void writeTuple(JsonGenerator jsonGenerator, String name, int value) throws IOException {
    jsonGenerator.writeStartObject();
    jsonGenerator.writeNumberField(name, value);
    jsonGenerator.writeEndObject();
}
 
Example 12
Source File: ServiceResponseBuilder.java    From WSPerfLab with Apache License 2.0 4 votes vote down vote up
public static ByteArrayOutputStream buildTestAResponse(JsonFactory jsonFactory,
        BackendResponse responseA, BackendResponse responseB,
        BackendResponse responseC, BackendResponse responseD,
        BackendResponse responseE) throws IOException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    JsonGenerator jsonGenerator = jsonFactory.createJsonGenerator(bos);

    jsonGenerator.writeStartObject();
    // multiplication of C, D, E responseKey
    jsonGenerator.writeNumberField("responseKey", responseC.getResponseKey() + responseD.getResponseKey() +
            responseE.getResponseKey());

    // delay values of each response
    jsonGenerator.writeArrayFieldStart("delay");
    writeTuple(jsonGenerator, "a", responseA.getDelay());
    writeTuple(jsonGenerator, "b", responseB.getDelay());
    writeTuple(jsonGenerator, "c", responseC.getDelay());
    writeTuple(jsonGenerator, "d", responseD.getDelay());
    writeTuple(jsonGenerator, "e", responseE.getDelay());
    jsonGenerator.writeEndArray();

    // itemSize values of each response
    jsonGenerator.writeArrayFieldStart("itemSize");
    writeTuple(jsonGenerator, "a", responseA.getItemSize());
    writeTuple(jsonGenerator, "b", responseB.getItemSize());
    writeTuple(jsonGenerator, "c", responseC.getItemSize());
    writeTuple(jsonGenerator, "d", responseD.getItemSize());
    writeTuple(jsonGenerator, "e", responseE.getItemSize());
    jsonGenerator.writeEndArray();

    // numItems values of each response
    jsonGenerator.writeArrayFieldStart("numItems");
    writeTuple(jsonGenerator, "a", responseA.getNumItems());
    writeTuple(jsonGenerator, "b", responseB.getNumItems());
    writeTuple(jsonGenerator, "c", responseC.getNumItems());
    writeTuple(jsonGenerator, "d", responseD.getNumItems());
    writeTuple(jsonGenerator, "e", responseE.getNumItems());
    jsonGenerator.writeEndArray();

    // all items from responses
    jsonGenerator.writeArrayFieldStart("items");
    addItemsFromResponse(jsonGenerator, responseA);
    addItemsFromResponse(jsonGenerator, responseB);
    addItemsFromResponse(jsonGenerator, responseC);
    addItemsFromResponse(jsonGenerator, responseD);
    addItemsFromResponse(jsonGenerator, responseE);
    jsonGenerator.writeEndArray();

    jsonGenerator.writeEndObject();
    jsonGenerator.close();

    return bos;
}
 
Example 13
Source File: ServiceResponseBuilder.java    From WSPerfLab with Apache License 2.0 4 votes vote down vote up
private static void writeTuple(JsonGenerator jsonGenerator, String name, int value) throws IOException {
    jsonGenerator.writeStartObject();
    jsonGenerator.writeNumberField(name, value);
    jsonGenerator.writeEndObject();
}
 
Example 14
Source File: StartupProgressServlet.java    From hadoop with Apache License 2.0 3 votes vote down vote up
/**
 * Writes a JSON number field only if the value is defined.
 * 
 * @param json JsonGenerator to receive output
 * @param key String key to put
 * @param value long value to put
 * @throws IOException if there is an I/O error
 */
private static void writeNumberFieldIfDefined(JsonGenerator json, String key,
    long value) throws IOException {
  if (value != Long.MIN_VALUE) {
    json.writeNumberField(key, value);
  }
}
 
Example 15
Source File: StartupProgressServlet.java    From big-c with Apache License 2.0 3 votes vote down vote up
/**
 * Writes a JSON number field only if the value is defined.
 * 
 * @param json JsonGenerator to receive output
 * @param key String key to put
 * @param value long value to put
 * @throws IOException if there is an I/O error
 */
private static void writeNumberFieldIfDefined(JsonGenerator json, String key,
    long value) throws IOException {
  if (value != Long.MIN_VALUE) {
    json.writeNumberField(key, value);
  }
}