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


Java JsonEncoding类代码示例

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


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

示例1: AvroFileInputStream

import org.codehaus.jackson.JsonEncoding; //导入依赖的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

示例2: writeInternal

import org.codehaus.jackson.JsonEncoding; //导入依赖的package包/类
@Override
protected void writeInternal(Object object, HttpOutputMessage outputMessage)
		throws IOException, HttpMessageNotWritableException {

	JsonEncoding encoding = getJsonEncoding(outputMessage.getHeaders().getContentType());
	JsonGenerator jsonGenerator =
			this.objectMapper.getJsonFactory().createJsonGenerator(outputMessage.getBody(), encoding);

	// A workaround for JsonGenerators not applying serialization features
	// https://github.com/FasterXML/jackson-databind/issues/12
	if (this.objectMapper.getSerializationConfig().isEnabled(SerializationConfig.Feature.INDENT_OUTPUT)) {
		jsonGenerator.useDefaultPrettyPrinter();
	}

	try {
		if (this.jsonPrefix != null) {
			jsonGenerator.writeRaw(this.jsonPrefix);
		}
		this.objectMapper.writeValue(jsonGenerator, object);
	}
	catch (JsonProcessingException ex) {
		throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getMessage(), ex);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:25,代码来源:MappingJacksonHttpMessageConverter.java

示例3: getJsonStringFromRecord

import org.codehaus.jackson.JsonEncoding; //导入依赖的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: JsonObjectMapperWriter

import org.codehaus.jackson.JsonEncoding; //导入依赖的package包/类
public JsonObjectMapperWriter(OutputStream output, boolean prettyPrint) throws IOException {
  ObjectMapper mapper = new ObjectMapper();
  mapper.configure(
      SerializationConfig.Feature.CAN_OVERRIDE_ACCESS_MODIFIERS, true);

  // define a module
  SimpleModule module = new SimpleModule("Default Serializer",  
                                         new Version(0, 1, 1, "FINAL"));
  // add various serializers to the module
  //   add default (all-pass) serializer for all rumen specific data types
  module.addSerializer(DataType.class, new DefaultRumenSerializer());
  //   add a serializer to use object.toString() while serializing
  module.addSerializer(ID.class, new ObjectStringSerializer<ID>());
  
  // register the module with the object-mapper
  mapper.registerModule(module);

  mapper.getJsonFactory();
  writer = mapper.getJsonFactory().createJsonGenerator(
      output, JsonEncoding.UTF8);
  if (prettyPrint) {
    writer.useDefaultPrettyPrinter();
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:25,代码来源:JsonObjectMapperWriter.java

示例5: write

import org.codehaus.jackson.JsonEncoding; //导入依赖的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

示例6: createJsonGenerator

import org.codehaus.jackson.JsonEncoding; //导入依赖的package包/类
private JsonGenerator createJsonGenerator(Configuration conf, Path path) 
throws IOException {
  FileSystem outFS = path.getFileSystem(conf);
  CompressionCodec codec =
    new CompressionCodecFactory(conf).getCodec(path);
  OutputStream output;
  Compressor compressor = null;
  if (codec != null) {
    compressor = CodecPool.getCompressor(codec);
    output = codec.createOutputStream(outFS.create(path), compressor);
  } else {
    output = outFS.create(path);
  }

  JsonGenerator outGen = outFactory.createJsonGenerator(output, 
                                                        JsonEncoding.UTF8);
  outGen.useDefaultPrettyPrinter();
  
  return outGen;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:21,代码来源:Anonymizer.java

示例7: main

import org.codehaus.jackson.JsonEncoding; //导入依赖的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

示例8: getJsonEncoding

import org.codehaus.jackson.JsonEncoding; //导入依赖的package包/类
protected JsonEncoding getJsonEncoding(MediaType contentType) {
    if(contentType != null && contentType.getCharSet() != null) {
        Charset charset = contentType.getCharSet();
        JsonEncoding[] var3 = JsonEncoding.values();
        int var4 = var3.length;

        for(int var5 = 0; var5 < var4; ++var5) {
            JsonEncoding encoding = var3[var5];
            if(charset.name().equals(encoding.getJavaName())) {
                return encoding;
            }
        }
    }

    return JsonEncoding.UTF8;
}
 
开发者ID:autumnkuang,项目名称:nenlvse1.0,代码行数:17,代码来源:CustomMappingJacksonJsonpView.java

示例9: createJsonGenerator

import org.codehaus.jackson.JsonEncoding; //导入依赖的package包/类
/**
 * This is a helper method which creates a JsonGenerator instance, for writing
 * the state of the ClusterManager to the state file. The JsonGenerator
 * instance writes to a compressed file if we have the compression flag
 * turned on.
 *
 * @param conf The CoronaConf instance to be used
 * @return The JsonGenerator instance to be used
 * @throws IOException
 */
public static JsonGenerator createJsonGenerator(CoronaConf conf)
  throws IOException {
  OutputStream outputStream = new FileOutputStream(conf.getCMStateFile());
  if (conf.getCMCompressStateFlag()) {
    outputStream = new GZIPOutputStream(outputStream);
  }
  ObjectMapper mapper = new ObjectMapper();
  JsonGenerator jsonGenerator =
    new JsonFactory().createJsonGenerator(outputStream, JsonEncoding.UTF8);
  jsonGenerator.setCodec(mapper);
  if (!conf.getCMCompressStateFlag()) {
    jsonGenerator.setPrettyPrinter(new DefaultPrettyPrinter());
  }
  return jsonGenerator;
}
 
开发者ID:rhli,项目名称:hadoop-EAR,代码行数:26,代码来源:CoronaSerializer.java

示例10: writeToResponse

import org.codehaus.jackson.JsonEncoding; //导入依赖的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

示例11: AvroFileInputStream

import org.codehaus.jackson.JsonEncoding; //导入依赖的package包/类
public AvroFileInputStream(FileStatus status) throws IOException {
  pos = 0;
  buffer = new byte[0];
  GenericDatumReader<Object> reader = new GenericDatumReader<Object>();
  fileReader =
    DataFileReader.openReader(new File(status.getPath().toUri()), 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:ict-carch,项目名称:hadoop-plus,代码行数:17,代码来源:Display.java

示例12: writeInternal

import org.codehaus.jackson.JsonEncoding; //导入依赖的package包/类
@Override
protected void writeInternal(Object object, HttpOutputMessage outputMessage)
		throws IOException, HttpMessageNotWritableException {

	JsonEncoding encoding = getJsonEncoding(outputMessage.getHeaders().getContentType());
	JsonGenerator jsonGenerator =
			this.objectMapper.getJsonFactory().createJsonGenerator(outputMessage.getBody(), encoding);
	try {
		if (this.prefixJson) {
			jsonGenerator.writeRaw("{} && ");
		}
		this.objectMapper.writeValue(jsonGenerator, object);
	}
	catch (IOException ex) {
		throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getMessage(), ex);
	}
}
 
开发者ID:bestarandyan,项目名称:ShoppingMall,代码行数:18,代码来源:MappingJacksonHttpMessageConverter.java

示例13: write

import org.codehaus.jackson.JsonEncoding; //导入依赖的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

示例14: writeInternal

import org.codehaus.jackson.JsonEncoding; //导入依赖的package包/类
@Override
protected void writeInternal(Object o, HttpOutputMessage outputMessage)
		throws IOException, HttpMessageNotWritableException {
	JsonEncoding encoding = getEncoding(outputMessage.getHeaders()
			.getContentType());
	JsonGenerator jsonGenerator = this.objectMapper.getJsonFactory()
			.createJsonGenerator(outputMessage.getBody(), encoding);
	if (this.prefixJson) {
		jsonGenerator.writeRaw("{} && ");
	}
	this.objectMapper.writeValue(jsonGenerator, o);
	ByteArrayOutputStream baos = new ByteArrayOutputStream();
	JsonGenerator baosjsonGenerator = this.objectMapper.getJsonFactory()
			.createJsonGenerator(baos, encoding);
	this.objectMapper.writeValue(baosjsonGenerator, o);
	logger.debug("Middleware returns " + o.getClass().getName() + " "
			+ baos.toString());
}
 
开发者ID:Appverse,项目名称:appverse-server,代码行数:19,代码来源:CustomMappingJacksonHttpMessageConverter.java

示例15: generate

import org.codehaus.jackson.JsonEncoding; //导入依赖的package包/类
public void generate(ZipOutputStream out) {
	try {
		log.debug("开始处理taskCommandDefinition.data文件。。。");
		ProcessEngineConfigurationImpl processEngineConfigurationImpl = FoxBpmUtil.getProcessEngine().getProcessEngineConfiguration();
		List<TaskCommandDefinition> list = processEngineConfigurationImpl.getTaskCommandDefinitions();
		ObjectMapper objectMapper = new ObjectMapper();
		JsonGenerator jsonGenerator = objectMapper.getJsonFactory().createJsonGenerator(out, JsonEncoding.UTF8);
		String tmpEntryName = "cache/taskCommandDefinition.data";
		ZipEntry zipEntry = new ZipEntry(tmpEntryName);
		zipEntry.setMethod(ZipEntry.DEFLATED);// 设置条目的压缩方式
		out.putNextEntry(zipEntry);
		jsonGenerator.writeObject(list);
		out.closeEntry();
		log.debug("处理taskCommandDefinition.data文件完毕");
	} catch (Exception ex) {
		log.error("解析taskCommandDefinition.data文件失败!生成zip文件失败!");
		throw new FoxBPMException("解析taskCommandDefinition.data文件失败", ex);
	}
}
 
开发者ID:FoxBPM,项目名称:FoxBPM,代码行数:20,代码来源:TaskCommandDefinitionsGenerator.java


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