Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
On this PR:
file
field final and create constructor that accepts aFile
to make it immutable, then remove setter.try-with-resources
to handle automatically closing of resources, that is, the file. The original code didn't even bother closing the resources.FileReader
andFileWriter
instead ofFileInputStream
andFileOutputStream
as a higher level and better abstraction to read a file.BufferedReader
to read the file line by line instead of char by char since IO operations are a bottleneck and that makes it faster.BufferedReader
to strip out non-ASCII characters since that's done in memory and is faster than reading char by char and ignoring non-ASCI characters because IO involving disk is slower.getFile()
doesn't need to besynchronized
since thefile
field is immutableJavadoc
since the original one was uselessBufferedReader
andBufferedWriter
are thread safe and we have an immutable instance of aFile
, we don't need to do anything else to ensure that this class is thread safe.What else would I had done if I had more than 15 minutes to spend:
java.ioFile
, and also rename the class.CompletableFuture<String>
or a RxJava Observable like `Single instead of a String. That would perform better when handling multiple large files.