Example usage for android.util JsonWriter JsonWriter

List of usage examples for android.util JsonWriter JsonWriter

Introduction

In this page you can find the example usage for android.util JsonWriter JsonWriter.

Prototype

public JsonWriter(Writer out) 

Source Link

Document

Creates a new instance that writes a JSON-encoded stream to out .

Usage

From source file:com.fuzz.android.limelight.util.JSONTool.java

/**
 * Entry point writer method that starts the call of other writer methods.
 *
 * @param outputStream//from   ww w. ja v a 2  s. co m
 * @param book
 * @throws IOException
 */
public static void writeJSON(OutputStream outputStream, Book book) throws IOException {
    JsonWriter writer = new JsonWriter(new OutputStreamWriter(outputStream, "UTF-8"));
    writer.setIndent("  ");
    writeBook(writer, book);
    writer.close();
}

From source file:at.ac.tuwien.caa.docscan.logic.DataLog.java

private void writeJsonStream(OutputStream out, ArrayList<ShotLog> shotLogs) throws IOException {

    JsonWriter writer = new JsonWriter(new OutputStreamWriter(out, "UTF-8"));
    writer.setIndent("  ");
    writeList(writer, shotLogs);//from w w  w  . j  av a  2 s .  co m
    writer.close();

}

From source file:com.avalond.ad_blocak.MainActivity.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    Log.d("MainActivity", "onActivityResult: Received result=" + resultCode + " for request=" + requestCode);
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == REQUEST_FILE_OPEN && resultCode == RESULT_OK) {
        Uri selectedfile = data.getData(); //The uri with the location of the file

        try {//from w  w w  .  j a  va2 s.c o m
            Configuration newConfig = new Configuration();
            newConfig.read(
                    new JsonReader(new InputStreamReader(getContentResolver().openInputStream(selectedfile))));
            config = newConfig;
        } catch (Exception e) {
            Toast.makeText(this, "Cannot read file: " + e.getMessage(), Toast.LENGTH_SHORT).show();
        }
        reload();
        FileHelper.writeSettings(this, MainActivity.config);
    }
    if (requestCode == REQUEST_FILE_STORE && resultCode == RESULT_OK) {
        Uri selectedfile = data.getData(); //The uri with the location of the file
        JsonWriter writer = null;
        try {
            writer = new JsonWriter(
                    new OutputStreamWriter(getContentResolver().openOutputStream(selectedfile)));
            config.write(writer);
            writer.close();
        } catch (Exception e) {
            Toast.makeText(this, "Cannot write file: " + e.getMessage(), Toast.LENGTH_SHORT).show();
        } finally {
            try {
                writer.close();
            } catch (Exception ignored) {

            }
        }
        reload();
    }
    if (requestCode == REQUEST_ITEM_EDIT && resultCode == RESULT_OK) {
        Configuration.Item item = new Configuration.Item();
        Log.d("FOOOO", "onActivityResult: item title = " + data.getStringExtra("ITEM_TITLE"));
        item.title = data.getStringExtra("ITEM_TITLE");
        item.location = data.getStringExtra("ITEM_LOCATION");
        item.state = data.getIntExtra("ITEM_STATE", 0);
        this.itemChangedListener.onItemChanged(item);
    }
}

From source file:org.opensilk.music.ui2.loader.PluginLoader.java

public void writeDisabledPlugins(List<ComponentName> plugins) {
    StringWriter sw = new StringWriter(100);
    JsonWriter jw = new JsonWriter(sw);
    try {/*from ww  w.j  ava  2s  . c  om*/
        jw.beginArray();
        for (ComponentName cn : plugins) {
            jw.value(cn.flattenToString());
        }
        jw.endArray();
        Timber.v("Write disabled plugins=" + sw.toString());
        settings.putString(PREF_DISABLED_PLUGINS, sw.toString());
    } catch (IOException e) {
        settings.remove(PREF_DISABLED_PLUGINS);
    } finally {
        IOUtils.closeQuietly(jw);
    }
}

From source file:ngo.music.soundcloudplayer.controller.SongController.java

/**
 * Write stack played song for play previous OfflineSong
 * /*from  www  .java  2 s .c o m*/
 * @param stackSongplayed
 * @param jsonWriter
 * @param currentTIme
 * @throws IOException
 */
public void storePlayingSong() throws IOException {
    // TODO Auto-generated method stub
    OfflineSong song = (OfflineSong) MusicPlayerService.getInstance().getCurrentSong();
    long curTime = MusicPlayerService.getInstance().getCurrentTime();
    ArrayList<Song> queue = MusicPlayerService.getInstance().getQueue();
    File file = new File(MusicPlayerService.getInstance().getApplicationContext()
            .getExternalFilesDir(Context.ACCESSIBILITY_SERVICE), filename);

    file.createNewFile();

    FileOutputStream fileOutputStream = new FileOutputStream(file);
    OutputStreamWriter fileWriter = new OutputStreamWriter(fileOutputStream);
    JsonWriter jsonWriter = new JsonWriter(fileWriter);
    writePlayedSongs(song, queue, jsonWriter, curTime);
    jsonWriter.close();
}