本文整理汇总了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());
}
示例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();
}
}
示例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;
}
示例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;
}
示例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());
}
示例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());
}
示例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();
}
示例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());
}
示例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());
}
示例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());
}
示例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());
}
}
示例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();
}
示例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());
}
示例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();
}