-
Notifications
You must be signed in to change notification settings - Fork 207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Perf: use buffered streams for IO #307
Changes from 2 commits
7be488e
986f93d
e00ff45
4969511
8564c42
0c11014
7e57e92
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,11 @@ | |
import android.support.annotation.NonNull; | ||
import android.support.annotation.Nullable; | ||
|
||
import java.io.BufferedWriter; | ||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.io.FileWriter; | ||
import java.io.OutputStreamWriter; | ||
import java.io.Writer; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
|
@@ -69,7 +72,8 @@ String write(@NonNull T streamable) { | |
|
||
Writer out = null; | ||
try { | ||
out = new FileWriter(filename); | ||
FileOutputStream fos = new FileOutputStream(filename); | ||
out = new BufferedWriter(new OutputStreamWriter(fos, "UTF-8")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do any of these objects also need closing? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed by other inline comment on JsonStream |
||
|
||
JsonStream stream = new JsonStream(out); | ||
stream.value(streamable); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not related to this PR but should we be closing this stream on the next line in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that would make more sense than closing two separate streams. I've updated the PR so that we do this. |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,12 @@ | |
import android.support.annotation.NonNull; | ||
import android.support.annotation.Nullable; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.File; | ||
import java.io.FileReader; | ||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.io.Reader; | ||
import java.io.Writer; | ||
|
||
public class JsonStream extends JsonWriter { | ||
|
@@ -53,9 +56,10 @@ public void value(@NonNull File file) throws IOException { | |
beforeValue(false); // add comma if in array | ||
|
||
// Copy the file contents onto the stream | ||
FileReader input = null; | ||
Reader input = null; | ||
try { | ||
input = new FileReader(file); | ||
FileInputStream fis = new FileInputStream(file); | ||
input = new BufferedReader(new InputStreamReader(fis, "UTF-8")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do any of these objects also need closing? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe calling |
||
IOUtils.copy(input, out); | ||
} finally { | ||
IOUtils.closeQuietly(input); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do any of these other objects need to be
closed
?