Java Code Examples for android.util.JsonWriter#close()

The following examples show how to use android.util.JsonWriter#close() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GeneralPreferenceFragment.java    From NClientV2 with Apache License 2.0 6 votes vote down vote up
private String getDataSettings(Context context)throws IOException{
    String[]names=new String[]{"Settings","ScrapedTags"};
    StringWriter sw=new StringWriter();
    JsonWriter writer=new JsonWriter(sw);
    writer.setIndent("\t");

    writer.beginObject();
    for(String name:names)
        processSharedFromName(writer,context,name);
    writer.endObject();

    writer.flush();
    String settings=sw.toString();
    writer.close();

    LogUtility.d(settings);
    return settings;
}
 
Example 2
Source File: TypeTransmogrifier.java    From cwac-saferoom with Apache License 2.0 6 votes vote down vote up
@TypeConverter
public static String fromStringSet(Set<String> strings) {
  if (strings==null) {
    return(null);
  }

  StringWriter result=new StringWriter();
  JsonWriter json=new JsonWriter(result);

  try {
    json.beginArray();

    for (String s : strings) {
      json.value(s);
    }

    json.endArray();
    json.close();
  }
  catch (IOException e) {
    Log.e(TAG, "Exception creating JSON", e);
  }

  return(result.toString());
}
 
Example 3
Source File: SessionStorage.java    From androdns with Apache License 2.0 6 votes vote down vote up
public static void save(Context context, String filename, ArrayList<Session> sessions) {
    try {

        FileOutputStream fos = context.openFileOutput(filename, Context.MODE_PRIVATE);

        JsonWriter writer = new JsonWriter(new OutputStreamWriter(fos, "UTF-8"));
        writer.setIndent("  ");
        writer.beginArray();
        for (Session s : sessions) {
            s.toJSON(writer);
        }
        writer.endArray();
        writer.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}