Code example for JsonWriter

Methods: beginArray

        if (mFile == null) throw new FileNotFoundException();
        try { 
            final JsonWriter jsonWriter = createJsonWriter(mContext, mFile);
            if (jsonWriter == null) throw new IOException("Could not create JsonWriter");
            mJsonWriter = jsonWriter;
            mHasWrittenData = true;
            return mJsonWriter;
        } catch (final IOException e) {
            if (DEBUG) {
                Log.w(TAG, "Exception when creating JsonWriter", e);
                Log.w(TAG, "Closing JsonWriter");
            if (mJsonWriter != null) mJsonWriter.close();
            mJsonWriter = null;
            throw e;
     * Create the JsonWriter to write the ResearchLog to. 
     * This method may be overriden in testing to redirect the output. 
    /* package for test */ JsonWriter createJsonWriter(final Context context, final File file)
            throws IOException { 
        return new JsonWriter(new BufferedWriter(new OutputStreamWriter(
                context.openFileOutput(file.getName(), Context.MODE_PRIVATE))));
Experience pair programming with AI  Get Codota for Java