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