当前位置: 首页>>代码示例>>Java>>正文


Java JsonGenerator.flush方法代码示例

本文整理汇总了Java中org.codehaus.jackson.JsonGenerator.flush方法的典型用法代码示例。如果您正苦于以下问题:Java JsonGenerator.flush方法的具体用法?Java JsonGenerator.flush怎么用?Java JsonGenerator.flush使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.codehaus.jackson.JsonGenerator的用法示例。


在下文中一共展示了JsonGenerator.flush方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: dumpConfiguration

import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
/**
 *  Writes out all the parameters and their properties (final and resource) to
 *  the given {@link Writer}
 *  The format of the output would be 
 *  { "properties" : [ {key1,value1,key1.isFinal,key1.resource}, {key2,value2,
 *  key2.isFinal,key2.resource}... ] } 
 *  It does not output the parameters of the configuration object which is 
 *  loaded from an input stream.
 * @param out the Writer to write to
 * @throws IOException
 */
public static void dumpConfiguration(Configuration config,
    Writer out) throws IOException {
  JsonFactory dumpFactory = new JsonFactory();
  JsonGenerator dumpGenerator = dumpFactory.createJsonGenerator(out);
  dumpGenerator.writeStartObject();
  dumpGenerator.writeFieldName("properties");
  dumpGenerator.writeStartArray();
  dumpGenerator.flush();
  synchronized (config) {
    for (Map.Entry<Object,Object> item: config.getProps().entrySet()) {
      dumpGenerator.writeStartObject();
      dumpGenerator.writeStringField("key", (String) item.getKey());
      dumpGenerator.writeStringField("value",
                                     config.get((String) item.getKey()));
      dumpGenerator.writeBooleanField("isFinal",
                                      config.finalParameters.contains(item.getKey()));
      dumpGenerator.writeStringField("resource",
                                     config.updatingResource.get(item.getKey()));
      dumpGenerator.writeEndObject();
    }
  }
  dumpGenerator.writeEndArray();
  dumpGenerator.writeEndObject();
  dumpGenerator.flush();
}
 
开发者ID:rhli,项目名称:hadoop-EAR,代码行数:37,代码来源:Configuration.java

示例2: writeToResponse

import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
/**
 * Writes the response values back to the http response.  This allows the calling code to
 * parse the response values for display to the user.
 *
 * @param responseMap the response params to write to the http response
 * @param response the http response
 * @throws IOException
 */
private static void writeToResponse(Map<String, String> responseMap, HttpServletResponse response) throws IOException {
       // Note: setting the content-type to text/html because otherwise IE prompt the user to download
       // the result rather than handing it off to the GWT form response handler.
       // See JIRA issue https://issues.jboss.org/browse/SRAMPUI-103
	response.setContentType("text/html; charset=UTF8"); //$NON-NLS-1$
       JsonFactory f = new JsonFactory();
       JsonGenerator g = f.createJsonGenerator(response.getOutputStream(), JsonEncoding.UTF8);
       g.useDefaultPrettyPrinter();
       g.writeStartObject();
       for (java.util.Map.Entry<String, String> entry : responseMap.entrySet()) {
           String key = entry.getKey();
           String val = entry.getValue();
           g.writeStringField(key, val);
       }
       g.writeEndObject();
       g.flush();
       g.close();
}
 
开发者ID:Teiid-Designer,项目名称:teiid-webui,代码行数:27,代码来源:DataVirtUploadServlet.java

示例3: toString

import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
public String toString(boolean pretty) {
    try {
        StringWriter writer = new StringWriter();
        JsonGenerator gen = FACTORY.createJsonGenerator(writer);
        if (pretty)
            gen.useDefaultPrettyPrinter();

        if (this instanceof PrimitiveSchema || this instanceof UnionSchema) {
            gen.writeStartObject();
            gen.writeFieldName("type");
        }

        writeJSON(gen, new SchemaNames());

        if (this instanceof PrimitiveSchema || this instanceof UnionSchema) {
            gen.writeEndObject();
        }

        gen.flush();
        return writer.toString();
    } catch (IOException e) {
        throw new BaijiRuntimeException(e);
    }
}
 
开发者ID:adohe,项目名称:Bottlenose,代码行数:25,代码来源:Schema.java

示例4: write

import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
/**
 * The only public write interface
 * @param schema the object schema
 * @param obj the object
 * @param os the final output stream
 */
public void write(Schema schema, T obj, OutputStream os) {
    if (schema instanceof RecordSchema) {
        if (os != null) {
            try {
                RecordSchema recordSchema = (RecordSchema) schema;
                JsonGenerator g = FACTORY.createJsonGenerator(os, JsonEncoding.UTF8);
                writeRecord(recordSchema, obj, g);
                g.flush();
            } catch (IOException e) {
                throw new BaijiRuntimeException("Serialize process failed.", e);
            }
        } else {
            throw new BaijiRuntimeException("Output stream can't be null");
        }
    } else {
        throw new BaijiRuntimeException("schema must be RecordSchema");
    }
}
 
开发者ID:archcentric,项目名称:BaijiSerializer4J,代码行数:25,代码来源:SpecificJsonWriter.java

示例5: toString

import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
/**
 * Render this as <a href="http://json.org/">JSON</a>.
 *
 * @param pretty if true, pretty-print JSON.
 */
public String toString(boolean pretty) {
    try {
        StringWriter writer = new StringWriter();
        JsonGenerator gen = FACTORY.createJsonGenerator(writer);
        if (pretty) gen.useDefaultPrettyPrinter();

        if (this instanceof PrimitiveSchema || this instanceof UnionSchema) {
            gen.writeStartObject();
            gen.writeFieldName("type");
        }

        writeJson(gen, new SchemaNames(), null);

        if (this instanceof PrimitiveSchema || this instanceof UnionSchema) {
            gen.writeEndObject();
        }

        gen.flush();
        return writer.toString();
    } catch (IOException e) {
        throw new BaijiRuntimeException(e);
    }
}
 
开发者ID:archcentric,项目名称:BaijiSerializer4J,代码行数:29,代码来源:Schema.java

示例6: toJson

import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:50,代码来源:Log4Json.java

示例7: dumpConfiguration

import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
/**
 *  Writes out all the parameters and their properties (final and resource) to
 *  the given {@link Writer}
 *  The format of the output would be 
 *  { "properties" : [ {key1,value1,key1.isFinal,key1.resource}, {key2,value2,
 *  key2.isFinal,key2.resource}... ] } 
 *  It does not output the parameters of the configuration object which is 
 *  loaded from an input stream.
 * @param out the Writer to write to
 * @throws IOException
 */
public static void dumpConfiguration(Configuration config,
    Writer out) throws IOException {
  JsonFactory dumpFactory = new JsonFactory();
  JsonGenerator dumpGenerator = dumpFactory.createJsonGenerator(out);
  dumpGenerator.writeStartObject();
  dumpGenerator.writeFieldName("properties");
  dumpGenerator.writeStartArray();
  dumpGenerator.flush();
  synchronized (config) {
    for (Map.Entry<Object,Object> item: config.getProps().entrySet()) {
      dumpGenerator.writeStartObject();
      dumpGenerator.writeStringField("key", (String) item.getKey());
      dumpGenerator.writeStringField("value", 
                                     config.get((String) item.getKey()));
      dumpGenerator.writeBooleanField("isFinal",
                                      config.finalParameters.contains(item.getKey()));
      String[] resources = config.updatingResource.get(item.getKey());
      String resource = UNKNOWN_RESOURCE;
      if(resources != null && resources.length > 0) {
        resource = resources[0];
      }
      dumpGenerator.writeStringField("resource", resource);
      dumpGenerator.writeEndObject();
    }
  }
  dumpGenerator.writeEndArray();
  dumpGenerator.writeEndObject();
  dumpGenerator.flush();
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:41,代码来源:Configuration.java

示例8: dumpConfiguration

import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
/***
 * Dumps the configuration of hierarchy of queues with 
 * the xml file path given. It is to be used directly ONLY FOR TESTING.
 * @param out the writer object to which dump is written to.
 * @param configFile the filename of xml file
 * @throws IOException
 */
static void dumpConfiguration(Writer out, String configFile,
    Configuration conf) throws IOException {
  if (conf != null && conf.get(DeprecatedQueueConfigurationParser.
      MAPRED_QUEUE_NAMES_KEY) != null) {
    return;
  }
  
  JsonFactory dumpFactory = new JsonFactory();
  JsonGenerator dumpGenerator = dumpFactory.createJsonGenerator(out);
  QueueConfigurationParser parser;
  boolean aclsEnabled = false;
  if (conf != null) {
    aclsEnabled = conf.getBoolean(MRConfig.MR_ACLS_ENABLED, false);
  }
  if (configFile != null && !"".equals(configFile)) {
    parser = new QueueConfigurationParser(configFile, aclsEnabled);
  }
  else {
    parser = getQueueConfigurationParser(null, false, aclsEnabled);
  }
  dumpGenerator.writeStartObject();
  dumpGenerator.writeFieldName("queues");
  dumpGenerator.writeStartArray();
  dumpConfiguration(dumpGenerator,parser.getRoot().getChildren());
  dumpGenerator.writeEndArray();
  dumpGenerator.writeEndObject();
  dumpGenerator.flush();
}
 
开发者ID:naver,项目名称:hadoop,代码行数:36,代码来源:QueueManager.java

示例9: open

import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
public Writer open(final PrintWriter writer) throws IOException {
  final JsonGenerator jg = jsonFactory.createJsonGenerator(writer);
  jg.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET);
  jg.useDefaultPrettyPrinter();
  jg.writeStartObject();
  return new Writer() {
    @Override
    public void flush() throws IOException {
      jg.flush();
    }

    @Override
    public void close() throws IOException {
      jg.close();
    }

    @Override
    public void write(String key, String value) throws JsonGenerationException, IOException {
      jg.writeStringField(key, value);
    }

    @Override
    public int write(MBeanServer mBeanServer, ObjectName qry, String attribute,
        boolean description)
    throws IOException {
      return JSONBean.write(jg, mBeanServer, qry, attribute, description);
    }
  };
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:30,代码来源:JSONBean.java

示例10: encodeDatabaseOperation

import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
/**
 * Encode the DownstreamOperation as a JSON record.
 * 
 * @param op the operatoin we are encoding
 * @return an instance of EventData
 * @throws IOException if an encoding error occurs
 */
public EventData encodeDatabaseOperation(DownstreamOperation op) throws IOException {
    JsonGenerator jg;

    eventHeader.setHeaderInfo(op);


    /*
     * need a new one of these with each call because we pass the byte array
     * from baos along with the event as it is passed to the publisher.
     */
    baos = new ByteArrayOutputStream();
    
    jg = factory.createJsonGenerator(baos);
    jg.writeStartObject();

    setTxInfo(jg, op);

    // loop through operatons with calls to appropriate jg.write() methods
    for (DownstreamColumnData col : op.getColumns()) {
        if (textOnly == true) {
            jg.writeStringField(col.getBDName(), col.asString());
        } else {
            // Encode the data appropriately: handle numbers as numbers, etc.
            int jdbcType;
            jdbcType = op.getTableMeta().getColumn(col.getOrigName()).getJdbcType();
            encodeColumn(col, jdbcType, jg);
        }
    }
    
    if (includeBefores) {
        setBeforeInfo(jg, op);
    }

    jg.writeEndObject();
    jg.flush();
    jg.close();

    return new EventData(encoderType, eventHeader.getEventHeader(), baos.toByteArray());
}
 
开发者ID:oracle,项目名称:bdglue,代码行数:47,代码来源:JsonEncoder.java

示例11: getJsonStringFromList

import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
/**
 * Convert Map<String, String>[] to JackSon string
 *
 * @param list Array of Map<String,String>
 * @return jackson string
 */
public static String getJsonStringFromList(List<Map<String, String>> list) {
    try {
        StringWriter sw = new StringWriter();
        JsonGenerator gen = jf.createJsonGenerator(sw);
        new ObjectMapper().writeValue(gen, list);
        gen.flush();
        return sw.toString();
    } catch (Exception e) {
        log.error("JacksonUtil.getJsonStringFromMap error| ErrMsg: " + e.getMessage(), e);
        return null;
    }
}
 
开发者ID:SyncFree,项目名称:SwiftCloud,代码行数:19,代码来源:JsonUtil.java

示例12: getJsonStringFromMap

import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
/**
 * Convert Map<String, String> to JackSon string
 *
 * @param aMap Map
 * @return Map<String, String>
 */
public static String getJsonStringFromMap(Map<String, String> aMap) {
    try {
        StringWriter sw = new StringWriter();
        JsonGenerator gen = jf.createJsonGenerator(sw);
        new ObjectMapper().writeValue(gen, aMap);
        gen.flush();
        return sw.toString();
    } catch (Exception e) {
        log.error("ErrMsg: " + e.getMessage(), e);
        return null;
    }
}
 
开发者ID:SyncFree,项目名称:SwiftCloud,代码行数:19,代码来源:JsonUtil.java

示例13: getJsonStringFromMapMap

import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
/**
 * Convert Map<String, String> to JackSon string
 *
 * @param aMap Map
 * @return Map<String, String>
 */
public static String getJsonStringFromMapMap(Map<String, Map<String, String>> aMap) {
    try {
        StringWriter sw = new StringWriter();
        JsonGenerator gen = jf.createJsonGenerator(sw);
        new ObjectMapper().writeValue(gen, aMap);
        gen.flush();
        return sw.toString();
    } catch (Exception e) {
        log.error("ErrMsg: " + e.getMessage(), e);
        return null;
    }
}
 
开发者ID:SyncFree,项目名称:SwiftCloud,代码行数:19,代码来源:JsonUtil.java

示例14: energizationStreaming

import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
@POST
@Path("/streaming")
public Response energizationStreaming(String body, @Context GraphDatabaseService db) throws IndexNotFoundKernelException, IOException, SchemaRuleNotFoundException, IndexBrokenKernelException, EntityNotFoundException {
    HashMap input = Validators.getValidEquipmentIds(body);
    StreamingOutput stream = os -> {
        JsonGenerator jg = objectMapper.getJsonFactory().createJsonGenerator(os, JsonEncoding.UTF8);
        jg.writeStartArray();

        try (Transaction tx = db.beginTx()) {
            ThreadToStatementContextBridge ctx = dbapi.getDependencyResolver().resolveDependency(ThreadToStatementContextBridge.class);
            ReadOperations ops = ctx.get().readOperations();
            IndexDescriptor descriptor = ops.indexGetForLabelAndPropertyKey(equipmentLabelId, propertyEquipmentId);

            HashMap<Long, Double> equipmentMap = new HashMap<>();
            for (String equipmentId : (Collection<String>) input.get("ids")) {
                Cursor<NodeItem> nodes = ops.nodeCursorGetFromUniqueIndexSeek(descriptor, equipmentId);
                if (nodes.next()) {
                    long equipmentNodeId = nodes.get().id();
                    energized.add((int) equipmentNodeId);
                    jg.writeString(equipmentId);
                    equipmentMap.put(equipmentNodeId, (double) ops.nodeGetProperty(equipmentNodeId, propertyVoltage));

                    while (!equipmentMap.isEmpty()) {
                        Map.Entry<Long, Double> entry = equipmentMap.entrySet().iterator().next();
                        equipmentMap.remove(entry.getKey());
                        RelationshipIterator relationshipIterator = ops.nodeGetRelationships(entry.getKey(), org.neo4j.graphdb.Direction.BOTH);
                        Cursor<RelationshipItem> c;

                        while (relationshipIterator.hasNext()) {
                            c = ops.relationshipCursor(relationshipIterator.next());
                            if (c.next() && (boolean) c.get().getProperty(propertyIncomingSwitchOn) && (boolean) c.get().getProperty(propertyOutgoingSwitchOn)) {
                                long otherNodeId = c.get().otherNode(entry.getKey());
                                if (!energized.contains((int) otherNodeId)) {
                                    double newVoltage = (double) ops.nodeGetProperty(otherNodeId, propertyVoltage);
                                    if (newVoltage <= entry.getValue()) {
                                        jg.writeString((String) ops.nodeGetProperty(otherNodeId, propertyEquipmentId));
                                        energized.add((int) otherNodeId);
                                        equipmentMap.put(otherNodeId, newVoltage);
                                    }
                                }
                            }
                        }
                    }
                }
                nodes.close();
            }
            tx.success();
        } catch (Exception e) {
            e.printStackTrace();
        }

        jg.writeEndArray();
        jg.flush();
        jg.close();
    };
    return Response.ok().entity(stream).type(MediaType.APPLICATION_JSON).build();
}
 
开发者ID:maxdemarzi,项目名称:power_grid,代码行数:58,代码来源:Energization.java


注:本文中的org.codehaus.jackson.JsonGenerator.flush方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。