Example usage for android.util JsonWriter close

List of usage examples for android.util JsonWriter close

Introduction

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

Prototype

public void close() throws IOException 

Source Link

Document

Flushes and closes this writer and the underlying Writer .

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/*  w ww  .j  av  a2s. c  o 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 a v  a 2  s  .  c o  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 v a  2 s. c om*/
            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:ngo.music.soundcloudplayer.controller.SongController.java

/**
 * Write stack played song for play previous OfflineSong
 * /*from   w  w w. j  a  va  2  s .  c  om*/
 * @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();
}