當前位置: 首頁>>代碼示例>>Java>>正文


Java JsonWriter.close方法代碼示例

本文整理匯總了Java中android.util.JsonWriter.close方法的典型用法代碼示例。如果您正苦於以下問題:Java JsonWriter.close方法的具體用法?Java JsonWriter.close怎麽用?Java JsonWriter.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.util.JsonWriter的用法示例。


在下文中一共展示了JsonWriter.close方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: serializeStringCollection

import android.util.JsonWriter; //導入方法依賴的package包/類
/**
 * A generic serializer for string collections.
 *
 * @param collection Collection to serialize
 * @param <C>        A concrete collection class, e.g. {@code ArrayList<String>}.
 * @return JSON representation of the string collection.
 */
@NonNull
public static <C extends Collection<String>> String serializeStringCollection(@NonNull C collection) {
    StringWriter writer = new StringWriter();
    JsonWriter jsonWriter = new JsonWriter(writer);
    try {
        jsonWriter.beginArray();
        for (String s : collection) {
            jsonWriter.value(s);
        }
        jsonWriter.endArray();
        jsonWriter.close();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return writer.toString();
}
 
開發者ID:maskarade,項目名稱:Android-Orma,代碼行數:24,代碼來源:BuiltInSerializers.java

示例2: writeToJSON

import android.util.JsonWriter; //導入方法依賴的package包/類
private void writeToJSON(OutputStream out, Date date, Location loc) throws IOException {
    FileOutputStream outputStream;
    JsonWriter writer = new JsonWriter(new OutputStreamWriter(out, "UTF-8"));
    writer.setIndent("  ");
    writer.beginArray();

    writer.beginObject();
    writer.name("Date").value(date.toString());

    writer.name("Location");
    writer.beginArray();
    writer.value(loc.getLatitude());
    writer.value(loc.getLongitude());
    writer.endArray();

    writer.endObject();
    writer.close();
}
 
開發者ID:alexdao,項目名稱:footstep,代碼行數:19,代碼來源:MainActivity.java

示例3: save

import android.util.JsonWriter; //導入方法依賴的package包/類
@Override
public void save() {
    try {
        OutputStream out = SIAApp.SIA_APP.openFileOutput("news", Context.MODE_PRIVATE);
        JsonWriter writer = new JsonWriter(new OutputStreamWriter(out));

        writer.setIndent("  ");
        writer.beginArray();
        for(Entry s : this) {
            writer.beginObject();

            writer.name("id").value(s.id);
            writer.name("date").value(s.date.getTime());
            writer.name("topic").value(s.topic);
            writer.name("source").value(s.source);
            writer.name("title").value(s.title);
            writer.name("text").value(s.text);

            writer.endObject();
        }
        writer.endArray();
        writer.close();
    } catch(Exception e) {
        e.printStackTrace();
    }
}
 
開發者ID:Cedgetec,項目名稱:SchulinfoApp-android,代碼行數:27,代碼來源:News.java

示例4: save

import android.util.JsonWriter; //導入方法依賴的package包/類
public void save() {
    try {
        OutputStream out = SIAApp.SIA_APP.openFileOutput("mensa", Context.MODE_PRIVATE);
        JsonWriter writer = new JsonWriter(new OutputStreamWriter(out));

        writer.setIndent("  ");
        writer.beginArray();
        for(MensaItem s : this) {
            writer.beginObject();

            writer.name("id").value(s.id);
            writer.name("date").value(s.date);
            writer.name("meal").value(s.meal);
            writer.name("garnish").value(s.garnish);
            writer.name("dessert").value(s.dessert);
            writer.name("vegetarian").value(s.vegetarian);
            writer.name("image").value(s.image);

            writer.endObject();
        }
        writer.endArray();
        writer.close();
    } catch(Exception e) {
        e.printStackTrace();
    }
}
 
開發者ID:Cedgetec,項目名稱:SchulinfoApp-android,代碼行數:27,代碼來源:Mensa.java

示例5: write

import android.util.JsonWriter; //導入方法依賴的package包/類
public boolean write(final List<Person> persons,
		final OutputStream personStream) {
	final OutputStreamWriter ouw = new OutputStreamWriter(personStream,
			Charsets.UTF_8);
	final JsonWriter writer = new JsonWriter(ouw);
	try {
		writer.beginArray();
		for (final Person person : persons) {
			writePerson(person, writer);
		}
		writer.endArray();
		writer.close();
		return true;
	} catch (final IOException e) {
		Closeables.closeQuietly(writer);
	} finally {
		Closeables.closeQuietly(writer);
	}

	return false;
}
 
開發者ID:rduerig,項目名稱:nansai,代碼行數:22,代碼來源:PersonFileWriter.java

示例6: toJson

import android.util.JsonWriter; //導入方法依賴的package包/類
/**
 * Serializes the map into it's json representation into the provided {@link Writer}. If you want
 * to retrieve the json as a string,  use {@link #toJson(Map)} instead.
 */
public void toJson(Map<?, ?> map, Writer writer) throws IOException {
  if (map == null) {
    throw new IllegalArgumentException("map == null");
  }
  if (writer == null) {
    throw new IllegalArgumentException("writer == null");
  }

  JsonWriter jsonWriter = new JsonWriter(writer);
  jsonWriter.setLenient(isLenient);
  if (prettyPrint) {
    jsonWriter.setIndent("  ");
  }
  try {
    mapToWriter(map, jsonWriter);
  } finally {
    jsonWriter.close();
  }
}
 
開發者ID:segmentio,項目名稱:cartographer,代碼行數:24,代碼來源:Cartographer.java

示例7: toJson

import android.util.JsonWriter; //導入方法依賴的package包/類
/**
 * Serializes the map into it's json representation into the provided {@link Writer}. If you want
 * to retrieve the json as a string, use {@link #toJson(Map)} instead.
 */
public void toJson(Map<?, ?> map, Writer writer) throws IOException {
  if (map == null) {
    throw new IllegalArgumentException("map == null");
  }
  if (writer == null) {
    throw new IllegalArgumentException("writer == null");
  }

  JsonWriter jsonWriter = new JsonWriter(writer);
  jsonWriter.setLenient(isLenient);
  if (prettyPrint) {
    jsonWriter.setIndent("  ");
  }
  try {
    mapToWriter(map, jsonWriter);
  } finally {
    jsonWriter.close();
  }
}
 
開發者ID:segmentio,項目名稱:analytics-android,代碼行數:24,代碼來源:Cartographer.java

示例8: toJSON

import android.util.JsonWriter; //導入方法依賴的package包/類
public final void toJSON(JsonWriter writer) throws IOException {
    writer.beginObject();
    writer.name("ObjectType").value(getClass().getName());
    writer.name("Type").value(ui_type.ordinal());
    writer.name("Title").value(title);
    writer.name("Value").value(current_value);
    writer.name("max_value").value(max_value);
    writer.name("min_value").value(min_value);
    writer.name("Hidden").value(hidden);
    writer.name("UID").value(uid);
    if (needCredentials()) {
        if (deviceUID == null)
            throw new RuntimeException();
        writer.name("DeviceUID").value(deviceUID);
    }
    saveValue(writer);
    writer.name("Groups").beginArray();
    for (String groupUID : group_uids)
        writer.value(groupUID);
    writer.endArray();
    writer.endObject();
    writer.close();
}
 
開發者ID:davidgraeff,項目名稱:Android-NetPowerctrl,代碼行數:24,代碼來源:Executable.java

示例9: saveCache

import android.util.JsonWriter; //導入方法依賴的package包/類
/**
 * Save the cache to the specified location
 */
public static void saveCache()
{
	File file = new File(mClassCachePath + ".json");

	try
	{
		BufferedWriter out = new BufferedWriter(new FileWriter(file, false));

		JsonWriter writer = new JsonWriter(out);
		writer.setIndent("  ");
		writer.beginArray();

		for (CachedProfile item : mClassMap.values())
		{
			if (item.getUsed())
			{
				writer.beginObject();
				writer.name(TARGET_KEY).value(item.getTargetPath());
				writer.name(CLASS_KEY).value(item.getClassPath());
				writer.name(HOOK_KEY).value(item.getHookVersion());
				writer.name(MODULE_KEY).value(item.getModuleVersion());
				writer.name(SIMILARITY_KEY).value(item.getSimilarity());
				writer.endObject();
			}


		}

		writer.endArray();
		writer.close();
	}
	catch (Exception ex)
	{
		Log.e(TAG, "Failed to save profile cache");
		ex.printStackTrace();
	}
}
 
開發者ID:Nordskog,項目名稱:ClassHunter,代碼行數:41,代碼來源:ProfileCache.java

示例10: convert

import android.util.JsonWriter; //導入方法依賴的package包/類
@Override public RequestBody convert(Batch batch) throws IOException {
  Buffer buffer = new Buffer();
  JsonWriter writer = new JsonWriter(new OutputStreamWriter(buffer.outputStream()));
  JsonUtils.toJson(writer, batch);
  writer.close();
  return RequestBody.create(MEDIA_TYPE, buffer.readByteString());
}
 
開發者ID:f2prateek,項目名稱:segment-android,代碼行數:8,代碼來源:MessageRetrofitConverter.java

示例11: toStream

import android.util.JsonWriter; //導入方法依賴的package包/類
@Override public void toStream(Message m, OutputStream bytes) throws IOException {
  CountingOutputStream countingOutputStream = new CountingOutputStream(bytes);
  JsonWriter writer = new JsonWriter(new OutputStreamWriter(countingOutputStream));
  JsonUtils.toJson(writer, m);
  writer.close();

  long count = countingOutputStream.getCount();
  if (count > JsonUtils.MAX_MESSAGE_SIZE) {
    throw new JsonUtils.MessageTooLargeException(m, count);
  }
}
 
開發者ID:f2prateek,項目名稱:segment-android,代碼行數:12,代碼來源:MessageObjectQueueConverter.java

示例12: toJSON

import android.util.JsonWriter; //導入方法依賴的package包/類
public String toJSON() throws IOException {
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    JsonWriter writer = new JsonWriter(new OutputStreamWriter(byteArrayOutputStream, "UTF-8"));

    writer.beginObject();
    writer.name("sender_recipient").value(senderRecipient);
    writer.name("text").value(text);
    writer.endObject();
    writer.close();

    return byteArrayOutputStream.toString();
}
 
開發者ID:nerdinand,項目名稱:SMSGateway,代碼行數:13,代碼來源:SMSMessage.java

示例13: getJsonString

import android.util.JsonWriter; //導入方法依賴的package包/類
public String getJsonString(String name) {
    StringWriter swriter = new StringWriter();
    try {
        JsonWriter writer = new JsonWriter(swriter);
        writeJson(writer, name);
        writer.close();
    } catch (IOException e) {
        return null;
    }
    return swriter.toString();
}
 
開發者ID:asm-products,項目名稱:nexus-gallery,代碼行數:12,代碼來源:ImagePreset.java

示例14: writeJSONToStream

import android.util.JsonWriter; //導入方法依賴的package包/類
/**
 * Writes all the data from Database to passed outputstream in
 * JSON format
 * @param outputStream
 * @throws IOException
 */
public void writeJSONToStream(OutputStream outputStream) throws IOException {
    JsonWriter writer = new JsonWriter(new OutputStreamWriter(outputStream));
    writeParties(writer);
    writer.close();
    outputStream.close();
}
 
開發者ID:ndhunju,項目名稱:dailyJournal,代碼行數:13,代碼來源:JsonConverterStream.java

示例15: saveFilter

import android.util.JsonWriter; //導入方法依賴的package包/類
public static void saveFilter(Filter.FilterList list) {
    try {
        OutputStream out = SIAApp.SIA_APP.openFileOutput("ggfilterV2", Context.MODE_PRIVATE);
        JsonWriter writer = new JsonWriter(new OutputStreamWriter(out));
        writer.setIndent("  ");
        writer.beginArray();
        for(Filter.IncludingFilter inc : list.including) {
            writer.beginObject();
            writer.name("type").value(inc.getType().toString());
            writer.name("filter").value(inc.getFilter());
            writer.name("excluding").beginArray();
            for (Filter.ExcludingFilter f : inc.excluding) {
                writer.beginObject();
                writer.name("type").value(f.getType().toString());
                writer.name("filter").value(f.getFilter());
                writer.name("contains").value(f.contains);
                writer.endObject();
            }
            writer.endArray();
            writer.endObject();
        }
        writer.endArray();
        writer.close();
    } catch(Exception e) {
        e.printStackTrace();
    }
}
 
開發者ID:Cedgetec,項目名稱:SchulinfoApp-android,代碼行數:28,代碼來源:FilterActivity.java


注:本文中的android.util.JsonWriter.close方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。