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


Java JsonWriter.flush方法代码示例

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


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

示例1: convert

import com.google.gson.stream.JsonWriter; //导入方法依赖的package包/类
@Override
public RequestBody convert(T value) throws IOException {
  //if (String.class.getName().equals(value.getClass().getName())) {
  //  return RequestBody.create(MediaType.parse("text/plain"), value.toString());
  //}

  Buffer buffer = new Buffer();
  Writer writer = new OutputStreamWriter(buffer.outputStream(), UTF_8);
  JsonWriter jsonWriter = gson.newJsonWriter(writer);
  try {
    adapter.write(jsonWriter, value);
    jsonWriter.flush();
  } catch (IOException e) {
    throw new AssertionError(e); // Writing to Buffer does no I/O.
  } finally {
    jsonWriter.close();
  }

  return RequestBody.create(MEDIA_TYPE, buffer.readByteString());
}
 
开发者ID:Lingzh0ng,项目名称:BrotherWeather,代码行数:21,代码来源:PPRestRequestBodyConverter.java

示例2: run

import com.google.gson.stream.JsonWriter; //导入方法依赖的package包/类
public void run(OutputStream optionalOutput, boolean extractUnpublished) throws IOException {
  // fill sources with extra input:
  JsonDataSources sources = new ExtraInput().fetchAllDataSources();
  // fill sources with vendor API input:
  VendorDynamicInput vendorInput = new VendorDynamicInput();
  vendorInput.setExtractUnpublished(extractUnpublished);
  sources.putAll(vendorInput.fetchAllDataSources());
  // extract session data from inputs:
  JsonObject newData = new DataExtractor(false).extractFromDataSources(sources);

  // send data to the outputstream
  Writer writer = Channels.newWriter(Channels.newChannel(optionalOutput), "UTF-8");
  JsonWriter optionalOutputWriter = new JsonWriter(writer);
  optionalOutputWriter.setIndent("  ");
  new Gson().toJson(newData, optionalOutputWriter);
  optionalOutputWriter.flush();
}
 
开发者ID:dreaminglion,项目名称:iosched-reader,代码行数:18,代码来源:APIExtractor.java

示例3: convert

import com.google.gson.stream.JsonWriter; //导入方法依赖的package包/类
@Override public RequestBody convert(T value) throws IOException {
  //if (String.class.getName().equals(value.getClass().getName())) {
  //  return RequestBody.create(MediaType.parse("text/plain"), value.toString());
  //}

  Buffer buffer = new Buffer();
  Writer writer = new OutputStreamWriter(buffer.outputStream(), UTF_8);
  JsonWriter jsonWriter = gson.newJsonWriter(writer);
  try {
    adapter.write(jsonWriter, value);
    jsonWriter.flush();
  } catch (IOException e) {
    throw new AssertionError(e); // Writing to Buffer does no I/O.
  } finally {
    jsonWriter.close();
  }

  return RequestBody.create(MEDIA_TYPE, buffer.readByteString());
}
 
开发者ID:Lingzh0ng,项目名称:ITSM,代码行数:20,代码来源:PPRestRequestBodyConverter.java

示例4: serialize

import com.google.gson.stream.JsonWriter; //导入方法依赖的package包/类
/**
 * Serialize the metadata to a set of bytes.
 * @return the serialized bytes
 * @throws IOException
 */
protected byte[] serialize() throws IOException {
  ByteArrayOutputStream buffer = new ByteArrayOutputStream();
  JsonWriter writer = new JsonWriter(
      new OutputStreamWriter(buffer, Charsets.UTF_8));
  try {
    writer.beginObject();
    if (cipher != null) {
      writer.name(CIPHER_FIELD).value(cipher);
    }
    if (bitLength != 0) {
      writer.name(BIT_LENGTH_FIELD).value(bitLength);
    }
    if (created != null) {
      writer.name(CREATED_FIELD).value(created.getTime());
    }
    if (description != null) {
      writer.name(DESCRIPTION_FIELD).value(description);
    }
    if (attributes != null && attributes.size() > 0) {
      writer.name(ATTRIBUTES_FIELD).beginObject();
      for (Map.Entry<String, String> attribute : attributes.entrySet()) {
        writer.name(attribute.getKey()).value(attribute.getValue());
      }
      writer.endObject();
    }
    writer.name(VERSIONS_FIELD).value(versions);
    writer.endObject();
    writer.flush();
  } finally {
    writer.close();
  }
  return buffer.toByteArray();
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:39,代码来源:KeyProvider.java

示例5: main

import com.google.gson.stream.JsonWriter; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
	JsonObject json = convertToJSON("test2.thjson");
	StringWriter out = new StringWriter();
	JsonWriter writer = new JsonWriter(out);
	writer.setIndent("\t");
	Gson gson = new Gson();
	gson.toJson(json, writer);
	writer.flush();
	Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(out.getBuffer().toString()), null);
	System.out.println(out.getBuffer().toString());
}
 
开发者ID:Puppygames,项目名称:thjson,代码行数:12,代码来源:THJSONReader.java

示例6: jsonStringFromConfigureOutput

import com.google.gson.stream.JsonWriter; //导入方法依赖的package包/类
/**
     * Convert ConfigureOutput object to JSON String
     * @param object - ConfigureOutput object
     * @return - JSON string of ConfigureOutput
     */
    public final String jsonStringFromConfigureOutput(DataObject object) {
        final Writer writer = new StringWriter();
        JsonWriter jsonWriter = JsonWriterFactory.createJsonWriter(writer);
        final NormalizedNodeStreamWriter domWriter = JSONNormalizedNodeStreamWriter.createExclusiveWriter(JSONCodecFactory.create(context), CONFIGURE_OUTPUT_PATH, CONFIGURE_OUTPUT_PATH.getLastComponent().getNamespace(), jsonWriter);
        RestconfNormalizedNodeWriter restConfWriter = null;
        try {
        	jsonWriter.beginObject();
        	restConfWriter = (RestconfNormalizedNodeWriter) RestconfDelegatingNormalizedNodeWriter.forStreamWriter(domWriter);
			jsonWriter.name("output");
			for (DataContainerChild<? extends org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument, ?> child : codecRegistry.toNormalizedNodeRpcData((DataContainer)object).getValue()) {
	        	try {
					restConfWriter.write(child);
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (Exception e2){
					e2.printStackTrace();
				}
	        }
			jsonWriter.endObject();
	        restConfWriter.flush();
	        jsonWriter.flush();
		} catch (IOException e1) {
			e1.printStackTrace();
		}
        return writer.toString();
}
 
开发者ID:opendaylight,项目名称:fpc,代码行数:33,代码来源:FpcCodecUtils.java

示例7: process

import com.google.gson.stream.JsonWriter; //导入方法依赖的package包/类
private void process(HttpServletResponse resp, boolean showOnly) throws IOException {
  // everything ok, let's update
  StringBuilder summary = new StringBuilder();
  JsonObject contents = new JsonObject();
  JsonDataSources sources = new VendorDynamicInput().fetchAllDataSources();
  for (String entity: sources) {
    JsonArray array = new JsonArray();
    JsonDataSource source = sources.getSource(entity);
    for (JsonObject obj: source) {
      array.add(obj);
    }
    summary.append(entity).append(": ").append(source.size()).append("\n");
    contents.add(entity, array);
  }

  if (showOnly) {
    // Show generated contents to the output
    resp.setContentType("application/json");
    Writer writer = Channels.newWriter(Channels.newChannel(resp.getOutputStream()), "UTF-8");
    JsonWriter outputWriter = new JsonWriter(writer);
    outputWriter.setIndent("  ");
    new Gson().toJson(contents, outputWriter);
    outputWriter.flush();

  } else {
    // Write file to cloud storage
    CloudFileManager fileManager = new CloudFileManager();
    fileManager.createOrUpdate("__raw_session_data.json", contents, true);

    // send email
    Message message = new Message();
    message.setSender(Config.EMAIL_FROM);
    message.setSubject("[iosched-data-update] Manual sync from CMS");
    message.setTextBody(
        "Hey,\n\n"
        + "(this message is autogenerated)\n"
        + "This is a heads up that "+userService.getCurrentUser().getEmail()+" has just updated the IOSched 2015 data from the Vendor CMS.\n\n"
            + "Here is a brief status of what has been extracted from the Vendor API:\n"
            + summary
            + "\n\n"
            + "If you want to check the most current data that will soon be sync'ed to the IOSched Android app, "
            + "check this link: http://storage.googleapis.com/iosched-updater-dev.appspot.com/__raw_session_data.json\n"
            + "This data will remain unchanged until someone with proper privileges updates it again on https://iosched-updater-dev.appspot.com/cmsupdate\n\n"
            + "Thanks!\n\n"
            + "A robot on behalf of the IOSched team!\n\n"
            + "PS: you are receiving this either because you are an admin of the IOSched project or "
            + "because you are in a hard-coded list of I/O organizers. If you don't want to "
            + "receive it anymore, pay me a beer and ask kindly.");
    MailServiceFactory.getMailService().sendToAdmins(message);

    resp.sendRedirect("/admin/schedule/updateok.html");
  }
}
 
开发者ID:dreaminglion,项目名称:iosched-reader,代码行数:54,代码来源:CMSUpdateServlet.java


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