當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。