diff options
author | 2013-02-22 06:15:40 -0800 | |
---|---|---|
committer | 2013-02-22 06:15:40 -0800 | |
commit | 3e279243c1d8c959278c51234b8bc2221a609c56 (patch) | |
tree | 393902cfb23bb01d7c7dada8e97cc4bcd22b7fb7 /java/src/com/android/inputmethod/research/ResearchLog.java | |
parent | 6ff234ba70ded3feacdc3357c89e28fa00ec5575 (diff) | |
parent | c3252cfaf750d706f7280d32d1259e4367670bd9 (diff) | |
download | latinime-3e279243c1d8c959278c51234b8bc2221a609c56.tar.gz latinime-3e279243c1d8c959278c51234b8bc2221a609c56.tar.xz latinime-3e279243c1d8c959278c51234b8bc2221a609c56.zip |
am c3252cfa: Merge "[TestPrep7] Encapsulate JsonWriter creation"
* commit 'c3252cfaf750d706f7280d32d1259e4367670bd9':
[TestPrep7] Encapsulate JsonWriter creation
Diffstat (limited to 'java/src/com/android/inputmethod/research/ResearchLog.java')
-rw-r--r-- | java/src/com/android/inputmethod/research/ResearchLog.java | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/java/src/com/android/inputmethod/research/ResearchLog.java b/java/src/com/android/inputmethod/research/ResearchLog.java index 4dff17530..2303ebcfe 100644 --- a/java/src/com/android/inputmethod/research/ResearchLog.java +++ b/java/src/com/android/inputmethod/research/ResearchLog.java @@ -209,26 +209,37 @@ public class ResearchLog { public JsonWriter getInitializedJsonWriterLocked() { try { if (mJsonWriter == NULL_JSON_WRITER && mFile != null) { - final FileOutputStream fos = - mContext.openFileOutput(mFile.getName(), Context.MODE_PRIVATE); - mJsonWriter = new JsonWriter(new BufferedWriter(new OutputStreamWriter(fos))); - mJsonWriter.beginArray(); - mHasWrittenData = true; + final JsonWriter jsonWriter = createJsonWriter(mContext, mFile); + if (jsonWriter != null) { + jsonWriter.beginArray(); + mJsonWriter = jsonWriter; + mHasWrittenData = true; + } } } catch (IOException e) { - e.printStackTrace(); - Log.w(TAG, "Error in JsonWriter; disabling logging"); + Log.w(TAG, "Error in JsonWriter; disabling logging", e); try { mJsonWriter.close(); } catch (IllegalStateException e1) { // Assume that this is just the json not being terminated properly. // Ignore } catch (IOException e1) { - e1.printStackTrace(); + Log.w(TAG, "Error in closing JsonWriter; disabling logging", e1); } finally { mJsonWriter = NULL_JSON_WRITER; } } return mJsonWriter; } + + /** + * 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)))); + } } |