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


Java JsonFactory类代码示例

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


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

示例1: generateSLSLoadFile

import org.codehaus.jackson.JsonFactory; //导入依赖的package包/类
private static void generateSLSLoadFile(String inputFile, String outputFile)
        throws IOException {
  Reader input = new FileReader(inputFile);
  try {
    Writer output = new FileWriter(outputFile);
    try {
      ObjectMapper mapper = new ObjectMapper();
      ObjectWriter writer = mapper.writerWithDefaultPrettyPrinter();
      Iterator<Map> i = mapper.readValues(
              new JsonFactory().createJsonParser(input), Map.class);
      while (i.hasNext()) {
        Map m = i.next();
        output.write(writer.writeValueAsString(createSLSJob(m)) + EOL);
      }
    } finally {
      output.close();
    }
  } finally {
    input.close();
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:22,代码来源:RumenToSLSConverter.java

示例2: AvroFileInputStream

import org.codehaus.jackson.JsonFactory; //导入依赖的package包/类
public AvroFileInputStream(FileStatus status) throws IOException {
  pos = 0;
  buffer = new byte[0];
  GenericDatumReader<Object> reader = new GenericDatumReader<Object>();
  FileContext fc = FileContext.getFileContext(new Configuration());
  fileReader =
    DataFileReader.openReader(new AvroFSInput(fc, status.getPath()),reader);
  Schema schema = fileReader.getSchema();
  writer = new GenericDatumWriter<Object>(schema);
  output = new ByteArrayOutputStream();
  JsonGenerator generator =
    new JsonFactory().createJsonGenerator(output, JsonEncoding.UTF8);
  MinimalPrettyPrinter prettyPrinter = new MinimalPrettyPrinter();
  prettyPrinter.setRootValueSeparator(System.getProperty("line.separator"));
  generator.setPrettyPrinter(prettyPrinter);
  encoder = EncoderFactory.get().jsonEncoder(schema, generator);
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:18,代码来源:Display.java

示例3: getJsonStringFromRecord

import org.codehaus.jackson.JsonFactory; //导入依赖的package包/类
@Override
public String getJsonStringFromRecord(RecordField field)
        throws AvroUiSandboxServiceException {
    try {
        GenericRecord record = FormAvroConverter.createGenericRecordFromRecordField(field);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        JsonGenerator jsonGenerator
            = new JsonFactory().createJsonGenerator(baos, JsonEncoding.UTF8);
        jsonGenerator.useDefaultPrettyPrinter();
        JsonEncoder jsonEncoder = EncoderFactory.get().jsonEncoder(record.getSchema(), jsonGenerator);
        DatumWriter<GenericRecord> datumWriter = new GenericDatumWriter<GenericRecord>(record.getSchema());
        datumWriter.write(record, jsonEncoder);
        jsonEncoder.flush();
        baos.flush();            
        return new String(baos.toByteArray(), UTF8);
    } catch (Exception e) {
        throw Utils.handleException(e);
    }
}
 
开发者ID:kaaproject,项目名称:avro-ui,代码行数:20,代码来源:AvroUiSandboxServiceImpl.java

示例4: write

import org.codehaus.jackson.JsonFactory; //导入依赖的package包/类
private void write(DataOutput out) throws IOException {
  // This is just a JSON experiment
  System.out.println("Dumping the StatePool's in JSON format.");
  ObjectMapper outMapper = new ObjectMapper();
  outMapper.configure(
      SerializationConfig.Feature.CAN_OVERRIDE_ACCESS_MODIFIERS, true);
  // define a module
  SimpleModule module = new SimpleModule("State Serializer",  
      new Version(0, 1, 1, "FINAL"));
  // add the state serializer
  //module.addSerializer(State.class, new StateSerializer());

  // register the module with the object-mapper
  outMapper.registerModule(module);

  JsonFactory outFactory = outMapper.getJsonFactory();
  JsonGenerator jGen = 
    outFactory.createJsonGenerator((DataOutputStream)out, JsonEncoding.UTF8);
  jGen.useDefaultPrettyPrinter();

  jGen.writeObject(this);
  jGen.close();
}
 
开发者ID:naver,项目名称:hadoop,代码行数:24,代码来源:StatePool.java

示例5: main

import org.codehaus.jackson.JsonFactory; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
  final Configuration conf = new Configuration();
  final FileSystem lfs = FileSystem.getLocal(conf);

  for (String arg : args) {
    Path filePath = new Path(arg).makeQualified(lfs);
    String fileName = filePath.getName();
    if (fileName.startsWith("input")) {
      LoggedDiscreteCDF newResult = histogramFileToCDF(filePath, lfs);
      String testName = fileName.substring("input".length());
      Path goldFilePath = new Path(filePath.getParent(), "gold"+testName);

      ObjectMapper mapper = new ObjectMapper();
      JsonFactory factory = mapper.getJsonFactory();
      FSDataOutputStream ostream = lfs.create(goldFilePath, true);
      JsonGenerator gen = factory.createJsonGenerator(ostream,
          JsonEncoding.UTF8);
      gen.useDefaultPrettyPrinter();
      
      gen.writeObject(newResult);
      
      gen.close();
    } else {
      System.err.println("Input file not started with \"input\". File "+fileName+" skipped.");
    }
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:28,代码来源:TestHistograms.java

示例6: parseNodesFromSLSTrace

import org.codehaus.jackson.JsonFactory; //导入依赖的package包/类
/**
 * parse the sls trace file, return each host name
 */
public static Set<String> parseNodesFromSLSTrace(String jobTrace)
        throws IOException {
  Set<String> nodeSet = new HashSet<String>();
  JsonFactory jsonF = new JsonFactory();
  ObjectMapper mapper = new ObjectMapper();
  Reader input = new FileReader(jobTrace);
  try {
    Iterator<Map> i = mapper.readValues(
            jsonF.createJsonParser(input), Map.class);
    while (i.hasNext()) {
      Map jsonE = i.next();
      List tasks = (List) jsonE.get("job.tasks");
      for (Object o : tasks) {
        Map jsonTask = (Map) o;
        String hostname = jsonTask.get("container.host").toString();
        nodeSet.add(hostname);
      }
    }
  } finally {
    input.close();
  }
  return nodeSet;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:27,代码来源:SLSUtils.java

示例7: parseNodesFromNodeFile

import org.codehaus.jackson.JsonFactory; //导入依赖的package包/类
/**
 * parse the input node file, return each host name
 */
public static Set<String> parseNodesFromNodeFile(String nodeFile)
        throws IOException {
  Set<String> nodeSet = new HashSet<String>();
  JsonFactory jsonF = new JsonFactory();
  ObjectMapper mapper = new ObjectMapper();
  Reader input = new FileReader(nodeFile);
  try {
    Iterator<Map> i = mapper.readValues(
            jsonF.createJsonParser(input), Map.class);
    while (i.hasNext()) {
      Map jsonE = i.next();
      String rack = "/" + jsonE.get("rack");
      List tasks = (List) jsonE.get("nodes");
      for (Object o : tasks) {
        Map jsonNode = (Map) o;
        nodeSet.add(rack + "/" + jsonNode.get("node"));
      }
    }
  } finally {
    input.close();
  }
  return nodeSet;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:27,代码来源:SLSUtils.java

示例8: readJsonEntry

import org.codehaus.jackson.JsonFactory; //导入依赖的package包/类
/**
 * barファイルエントリからJSONファイルを読み込む.
 * @param <T> JSONMappedObject
 * @param inStream barファイルエントリのInputStream
 * @param entryName entryName
 * @param clazz clazz
 * @return JSONファイルから読み込んだオブジェクト
 * @throws IOException JSONファイル読み込みエラー
 */
public static <T> T readJsonEntry(
        InputStream inStream, String entryName, Class<T> clazz) throws IOException {
    JsonParser jp = null;
    ObjectMapper mapper = new ObjectMapper();
    JsonFactory f = new JsonFactory();
    jp = f.createJsonParser(inStream);
    JsonToken token = jp.nextToken(); // JSONルート要素("{")
    Pattern formatPattern = Pattern.compile(".*/+(.*)");
    Matcher formatMatcher = formatPattern.matcher(entryName);
    String jsonName = formatMatcher.replaceAll("$1");
    T json = null;
    if (token == JsonToken.START_OBJECT) {
        try {
            json = mapper.readValue(jp, clazz);
        } catch (UnrecognizedPropertyException ex) {
            throw PersoniumCoreException.BarInstall.JSON_FILE_FORMAT_ERROR.params(jsonName);
        }
    } else {
        throw PersoniumCoreException.BarInstall.JSON_FILE_FORMAT_ERROR.params(jsonName);
    }
    return json;
}
 
开发者ID:personium,项目名称:personium-core,代码行数:32,代码来源:BarFileUtils.java

示例9: getRequestBody

import org.codehaus.jackson.JsonFactory; //导入依赖的package包/类
/**
 * リクエストボディを解析してEventオブジェクトを取得する.
 * @param reader Http入力ストリーム
 * @return 解析したEventオブジェクト
 */
protected JSONEvent getRequestBody(final Reader reader) {
    JSONEvent event = null;
    JsonParser jp = null;
    ObjectMapper mapper = new ObjectMapper();
    JsonFactory f = new JsonFactory();
    try {
        jp = f.createJsonParser(reader);
        JsonToken token = jp.nextToken(); // JSONルート要素("{")
        if (token == JsonToken.START_OBJECT) {
            event = mapper.readValue(jp, JSONEvent.class);
        } else {
            throw PersoniumCoreException.Event.JSON_PARSE_ERROR;
        }
    } catch (IOException e) {
        throw PersoniumCoreException.Event.JSON_PARSE_ERROR;
    }
    return event;
}
 
开发者ID:personium,项目名称:personium-core,代码行数:24,代码来源:EventResource.java

示例10: JsonFactory

import org.codehaus.jackson.JsonFactory; //导入依赖的package包/类
/**
 * manifest.jsonのschema値がURL形式である場合trueが返却されること.
 * @throws IOException IOException
 */
@SuppressWarnings("unchecked")
@Test
public void manifest_jsonのschema値がURL形式である場合trueが返却されること() throws IOException {
    JsonFactory f = new JsonFactory();
    JSONObject json = new JSONObject();
    json.put("bar_version", "1");
    json.put("box_version", "1");
    json.put("DefaultPath", "boxName");
    json.put("schema", "http://app1.example.com/");
    JsonParser jp = f.createJsonParser(json.toJSONString());
    ObjectMapper mapper = new ObjectMapper();
    jp.nextToken();

    JSONManifest manifest = mapper.readValue(jp, JSONManifest.class);

    assertTrue(manifest.checkSchema());
}
 
开发者ID:personium,项目名称:personium-core,代码行数:22,代码来源:JSONManifestTest.java

示例11: JsonFactory

import org.codehaus.jackson.JsonFactory; //导入依赖的package包/类
/**
 * bar_versionを指定しない場合に例外がスローされる.
 */
@Test
@SuppressWarnings({"unchecked" })
public void bar_versionを指定しない場合に例外がスローされる() {
    JsonFactory f = new JsonFactory();
    JSONObject json = new JSONObject();
    json.put("box_version", "1");
    json.put("DefaultPath", "boxName");
    json.put("schema", "http://app1.example.com");

    try {
        JsonParser jp = f.createJsonParser(json.toJSONString());
        ObjectMapper mapper = new ObjectMapper();
        jp.nextToken();

        TestBarRunner testBarRunner = new TestBarRunner();
        testBarRunner.manifestJsonValidate(jp, mapper);
    } catch (PersoniumCoreException dce) {
        assertEquals(400, dce.getStatus());
        assertEquals("PR400-BI-0006", dce.getCode());
        return;
    } catch (Exception ex) {
        fail("Unexpected exception");
    }
    fail("PersoniumCoreExceptionが返却されない");
}
 
开发者ID:personium,项目名称:personium-core,代码行数:29,代码来源:BarFileValidateTest.java

示例12: constructGeometry

import org.codehaus.jackson.JsonFactory; //导入依赖的package包/类
private com.esri.core.geometry.Geometry constructGeometry(com.esri.ges.spatial.Geometry geo) throws Exception
{
	try{
		String jsonIn = geo.toJson();
		JsonFactory jf = new JsonFactory();
		JsonParser jp = jf.createJsonParser(jsonIn);
		MapGeometry mgeo = GeometryEngine.jsonToGeometry(jp);
		com.esri.core.geometry.Geometry geoIn= mgeo.getGeometry();
		return GeometryEngine.project(geoIn, srIn, srBuffer);
	}
	catch(Exception e)
	{
		LOG.error(e.getMessage());
		LOG.error(e.getStackTrace());
		throw(e);
	}
}
 
开发者ID:Esri,项目名称:defense-solutions-proofs-of-concept,代码行数:18,代码来源:QueryReportProcessor.java

示例13: parseNodesFromSLSTrace

import org.codehaus.jackson.JsonFactory; //导入依赖的package包/类
/**
 * parse the sls trace file, return each host name
 */
public static Set<String> parseNodesFromSLSTrace(String jobTrace)
        throws IOException {
  Set<String> nodeSet = new HashSet<String>();
  JsonFactory jsonF = new JsonFactory();
  ObjectMapper mapper = new ObjectMapper();
  Reader input =
      new InputStreamReader(new FileInputStream(jobTrace), "UTF-8");
  try {
    Iterator<Map> i = mapper.readValues(
            jsonF.createJsonParser(input), Map.class);
    while (i.hasNext()) {
      Map jsonE = i.next();
      List tasks = (List) jsonE.get("job.tasks");
      for (Object o : tasks) {
        Map jsonTask = (Map) o;
        String hostname = jsonTask.get("container.host").toString();
        nodeSet.add(hostname);
      }
    }
  } finally {
    input.close();
  }
  return nodeSet;
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:28,代码来源:SLSUtils.java

示例14: parseNodesFromNodeFile

import org.codehaus.jackson.JsonFactory; //导入依赖的package包/类
/**
 * parse the input node file, return each host name
 */
public static Set<String> parseNodesFromNodeFile(String nodeFile)
        throws IOException {
  Set<String> nodeSet = new HashSet<String>();
  JsonFactory jsonF = new JsonFactory();
  ObjectMapper mapper = new ObjectMapper();
  Reader input =
      new InputStreamReader(new FileInputStream(nodeFile), "UTF-8");
  try {
    Iterator<Map> i = mapper.readValues(
            jsonF.createJsonParser(input), Map.class);
    while (i.hasNext()) {
      Map jsonE = i.next();
      String rack = "/" + jsonE.get("rack");
      List tasks = (List) jsonE.get("nodes");
      for (Object o : tasks) {
        Map jsonNode = (Map) o;
        nodeSet.add(rack + "/" + jsonNode.get("node"));
      }
    }
  } finally {
    input.close();
  }
  return nodeSet;
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:28,代码来源:SLSUtils.java

示例15: generateSLSLoadFile

import org.codehaus.jackson.JsonFactory; //导入依赖的package包/类
private static void generateSLSLoadFile(String inputFile, String outputFile)
        throws IOException {
  try (Reader input =
      new InputStreamReader(new FileInputStream(inputFile), "UTF-8")) {
    try (Writer output =
        new OutputStreamWriter(new FileOutputStream(outputFile), "UTF-8")) {
      ObjectMapper mapper = new ObjectMapper();
      ObjectWriter writer = mapper.writerWithDefaultPrettyPrinter();
      Iterator<Map> i = mapper.readValues(
              new JsonFactory().createJsonParser(input), Map.class);
      while (i.hasNext()) {
        Map m = i.next();
        output.write(writer.writeValueAsString(createSLSJob(m)) + EOL);
      }
    }
  }
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:18,代码来源:RumenToSLSConverter.java


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