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


Java JsonWriter.close方法代码示例

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


在下文中一共展示了JsonWriter.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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,项目名称:ITSM,代码行数:20,代码来源:PPRestRequestBodyConverter.java

示例2: toMemJSONString

import com.google.gson.stream.JsonWriter; //导入方法依赖的package包/类
/**
 * Returns the JSON string representation of the current resources allocated
 * over time
 * 
 * @return the JSON string representation of the current resources allocated
 *         over time
 */
public String toMemJSONString() {
  StringWriter json = new StringWriter();
  JsonWriter jsonWriter = new JsonWriter(json);
  readLock.lock();
  try {
    jsonWriter.beginObject();
    // jsonWriter.name("timestamp").value("resource");
    for (Map.Entry<Long, Resource> r : cumulativeCapacity.entrySet()) {
      jsonWriter.name(r.getKey().toString()).value(r.getValue().toString());
    }
    jsonWriter.endObject();
    jsonWriter.close();
    return json.toString();
  } catch (IOException e) {
    // This should not happen
    return "";
  } finally {
    readLock.unlock();
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:28,代码来源:RLESparseResourceAllocation.java

示例3: toJSONString

import com.google.gson.stream.JsonWriter; //导入方法依赖的package包/类
/**
 * Serialize this fancy message, converting it into syntactically-valid JSON using a {@link JsonWriter}.
 * This JSON should be compatible with vanilla formatter commands such as {@code /tellraw}.
 *
 * @return The JSON string representing this object.
 */
public String toJSONString() {
	if (!dirty && jsonString != null) {
		return jsonString;
	}
	StringWriter string = new StringWriter();
	JsonWriter json = new JsonWriter(string);
	try {
		writeJson(json);
		json.close();
	} catch (IOException e) {
		throw new RuntimeException("invalid message");
	}
	jsonString = string.toString();
	dirty = false;
	return jsonString;
}
 
开发者ID:Slaymd,项目名称:CaulCrafting,代码行数:23,代码来源:FancyMessage.java

示例4: toJSONString

import com.google.gson.stream.JsonWriter; //导入方法依赖的package包/类
/**
 * Serialize this fancy message, converting it into syntactically-valid JSON using a {@link JsonWriter}.
 * This JSON should be compatible with vanilla formatter commands such as {@code /tellraw}.
 * @return The JSON string representing this object.
 */
public String toJSONString() {
	if (!dirty && jsonString != null) {
		return jsonString;
	}
	StringWriter string = new StringWriter();
	JsonWriter json = new JsonWriter(string);
	try {
		writeJson(json);
		json.close();
	} catch (IOException e) {
		throw new RuntimeException("invalid message");
	}
	jsonString = string.toString();
	dirty = false;
	return jsonString;
}
 
开发者ID:SamaGames,项目名称:SamaGamesAPI,代码行数:22,代码来源:FancyMessage.java

示例5: writeHistoryJson

import com.google.gson.stream.JsonWriter; //导入方法依赖的package包/类
@Override
public void writeHistoryJson(final OutputStream os, final List<Address> addresses) throws JsonWritingException {
    try {
        JsonWriter writer = new JsonWriter(new OutputStreamWriter(os, "UTF-8"));
        writer.setIndent("  ");
        writer.beginArray();
        for (Address address : addresses) {
            gson.toJson(address, Address.class, writer);
        }
        writer.endArray();
        writer.close();
    } catch (Exception e) {
        throw new JsonWritingException(e);
    }
}
 
开发者ID:RacZo,项目名称:Smarty-Streets-AutoCompleteTextView,代码行数:16,代码来源:GsonSmartyStreetsApiJsonParser.java

示例6: convert

import com.google.gson.stream.JsonWriter; //导入方法依赖的package包/类
@Override
public RequestBody convert(@NonNull T value) throws IOException {
    Buffer buffer = new Buffer();
    Writer writer = new OutputStreamWriter(buffer.outputStream(), UTF_8);
    JsonWriter jsonWriter = gson.newJsonWriter(writer);
    adapter.write(jsonWriter, value);
    jsonWriter.close();
    return RequestBody.create(MEDIA_TYPE, buffer.readByteString());
}
 
开发者ID:qiaodashaoye,项目名称:SuperHttp,代码行数:10,代码来源:GsonRequestBodyConverter.java

示例7: convert

import com.google.gson.stream.JsonWriter; //导入方法依赖的package包/类
@Override public RequestBody convert(T value) throws IOException {
  Buffer buffer = new Buffer();
  Writer writer = new OutputStreamWriter(buffer.outputStream(), UTF_8);
  JsonWriter jsonWriter = gson.newJsonWriter(writer);
  adapter.write(jsonWriter, value);
  jsonWriter.close();
  return RequestBody.create(MEDIA_TYPE, buffer.readByteString());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:9,代码来源:GsonRequestBodyConverter.java

示例8: beforeTest

import com.google.gson.stream.JsonWriter; //导入方法依赖的package包/类
@Before
public final void beforeTest() throws IOException {
	final FileWriter fileWriter = new FileWriter(CONFIG_DUMMY_PATH.toFile());
	final JsonWriter writer = new JsonWriter(fileWriter);
	writer.beginObject()
	.name("database").beginObject()
		.name("driverName").value(DRIVER_NAME)
		.endObject()
	.name("parser").beginObject()
		.name("resultsLimit").value(PARSER_LIMIT)
		.endObject()
	.endObject();
	writer.close();
	fileWriter.close();
}
 
开发者ID:JPDSousa,项目名称:rookit-core,代码行数:16,代码来源:ConfigTest.java

示例9: convert

import com.google.gson.stream.JsonWriter; //导入方法依赖的package包/类
@Override
public RequestBody convert(@NonNull T value) throws IOException {
  Buffer buffer = new Buffer();
  Writer writer = new OutputStreamWriter(buffer.outputStream(), UTF_8);
  JsonWriter jsonWriter = gson.newJsonWriter(writer);
  adapter.write(jsonWriter, value);
  jsonWriter.close();
  return RequestBody.create(MEDIA_TYPE, buffer.readByteString());
}
 
开发者ID:z-chu,项目名称:FriendBook,代码行数:10,代码来源:GsonRequestBodyConverter.java

示例10: convert

import com.google.gson.stream.JsonWriter; //导入方法依赖的package包/类
@Override
public RequestBody convert(T value) throws IOException {
    Buffer buffer = new Buffer();
    Writer writer = new OutputStreamWriter(buffer.outputStream(), UTF_8);
    JsonWriter jsonWriter = gson.newJsonWriter(writer);
    adapter.write(jsonWriter, value);
    jsonWriter.close();
    return RequestBody.create(MEDIA_TYPE, buffer.readByteString());
}
 
开发者ID:jeasinlee,项目名称:AndroidBasicLibs,代码行数:10,代码来源:GsonRequestBodyConverter.java

示例11: convert

import com.google.gson.stream.JsonWriter; //导入方法依赖的package包/类
@Override
public RequestBody convert(T value) throws IOException {
	Buffer buffer = new Buffer();
	Writer writer = new OutputStreamWriter(buffer.outputStream(), UTF_8);
	JsonWriter jsonWriter = gson.newJsonWriter(writer);
	adapter.write(jsonWriter, value);
	jsonWriter.close();
	return RequestBody.create(MEDIA_TYPE, buffer.readByteString());
}
 
开发者ID:vaibhav-sinha,项目名称:kong-java-client,代码行数:10,代码来源:CustomGsonRequestBodyConverter.java

示例12: saveChanges

import com.google.gson.stream.JsonWriter; //导入方法依赖的package包/类
private void saveChanges() {
    final StoredMemes storedMemes = convertToStoredMemes(this.cachedMemes.values());

    try {
        final JsonWriter jsonWriter = new JsonWriter(new FileWriter(saveFile));

        gson.toJson(storedMemes, StoredMemes.class, jsonWriter);

        jsonWriter.close();
    } catch (IOException e) {
        Log.e(JsonMemeDaoImpl.class.getName(), e.getMessage());
    }
}
 
开发者ID:daergoth,项目名称:dankbank,代码行数:14,代码来源:JsonMemeDaoImpl.java

示例13: 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:naver,项目名称:hadoop,代码行数:39,代码来源:KeyProvider.java

示例14: convert

import com.google.gson.stream.JsonWriter; //导入方法依赖的package包/类
@Override public RequestBody convert(T value) throws IOException {
    Buffer buffer = new Buffer();
    Writer writer = new OutputStreamWriter(buffer.outputStream(), UTF_8);
    JsonWriter jsonWriter = gson.newJsonWriter(writer);
    adapter.write(jsonWriter, value);
    jsonWriter.close();
    return RequestBody.create(MEDIA_TYPE, buffer.readByteString());
}
 
开发者ID:jenly1314,项目名称:KingTV,代码行数:9,代码来源:GsonRequestBodyConverter.java

示例15: execute

import com.google.gson.stream.JsonWriter; //导入方法依赖的package包/类
public void execute() throws IOException {
    RuntimeTypeAdapterFactory<DASTNodeLowLevel> nodeAdapter =
            RuntimeTypeAdapterFactory.of(DASTNodeLowLevel.class, "node")
                    .registerSubtype(DAPICallLowLevel.class, "DAPICall")
                    .registerSubtype(DBranchLowLevel.class, "DBranch")
                    .registerSubtype(DExceptLowLevel.class, "DExcept")
                    .registerSubtype(DLoopLowLevel.class, "DLoop")
                    .registerSubtype(DSubTreeLowLevel.class, "DSubTree");
    Gson gsonIn = new GsonBuilder().registerTypeAdapterFactory(nodeAdapter).
            serializeNulls().create();
    JsonReader reader = new JsonReader(new FileReader(inFile));

    Gson gsonOut = new GsonBuilder().serializeNulls().create();
    JsonWriter writer = new JsonWriter(new FileWriter(outFile));

    reader.beginObject();
    reader.nextName();
    reader.beginArray();

    writer.setIndent("  ");
    writer.beginObject();
    writer.name("programs");
    writer.beginArray();

    System.out.println();
    for (int i = 0; reader.hasNext(); i++) {
        System.out.print(String.format("\rProcessed %s programs", i));
        JSONInputWrapper inputProgram = gsonIn.fromJson(reader, JSONInputWrapper.class);
        JsonOutputWrapper outputProgram = new JsonOutputWrapper();

        outputProgram.file = inputProgram.file;
        outputProgram.ast = inputProgram.ast;
        outputProgram.low_level_sketch = inputProgram.ast.getLowLevelSketch();
        outputProgram.sequences = inputProgram.sequences;
        outputProgram.apicalls = inputProgram.apicalls;
        outputProgram.types = inputProgram.types;

        gsonOut.toJson(outputProgram, JsonOutputWrapper.class, writer);
    }
    System.out.println();

    reader.close();
    writer.endArray();
    writer.endObject();
    writer.close();
}
 
开发者ID:capergroup,项目名称:bayou,代码行数:47,代码来源:LowLevelSketchExtractor.java


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