Skip to content

Commit

Permalink
refactor: close jsonstream
Browse files Browse the repository at this point in the history
Close JsonStream rather than Writer, as this also closes the writer.
  • Loading branch information
fractalwrench committed May 9, 2018
1 parent e00ff45 commit 4969511
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
9 changes: 4 additions & 5 deletions sdk/src/main/java/com/bugsnag/android/DefaultHttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,16 @@ private int makeRequest(String urlString,
conn.addRequestProperty(entry.getKey(), entry.getValue());
}

OutputStream out = null;
JsonStream stream = null;

try {
out = conn.getOutputStream();
OutputStream out = conn.getOutputStream();
Charset charset = Charset.forName("UTF-8");
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out, charset));
JsonStream stream = new JsonStream(writer);
stream = new JsonStream(writer);
streamable.toStream(stream);
stream.close();
} finally {
IOUtils.closeQuietly(out);
IOUtils.closeQuietly(stream);
}


Expand Down
12 changes: 5 additions & 7 deletions sdk/src/main/java/com/bugsnag/android/FileStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,20 @@ String write(@NonNull T streamable) {

String filename = getFilename(streamable);

Writer out = null;

JsonStream stream = null;
try {
FileOutputStream fos = new FileOutputStream(filename);
out = new BufferedWriter(new OutputStreamWriter(fos, "UTF-8"));

JsonStream stream = new JsonStream(out);
Writer out = new BufferedWriter(new OutputStreamWriter(fos, "UTF-8"));
stream = new JsonStream(out);
stream.value(streamable);
stream.close();

Logger.info(String.format("Saved unsent payload to disk (%s) ", filename));
return filename;
} catch (Exception exception) {
Logger.warn(String.format("Couldn't save unsent payload to disk (%s) ",
filename), exception);
} finally {
IOUtils.closeQuietly(out);
IOUtils.closeQuietly(stream);
}
return null;
}
Expand Down

0 comments on commit 4969511

Please sign in to comment.