Should I buffer the InputStream or the InputStreamReader?

r1 is more efficient. The InputStreamReader itself doesn’t have a large buffer. The BufferedReader can be set to have a larger buffer than InputStreamReader. The InputStreamReader in r2 would act as a bottleneck. In a nut: you should read the data through a funnel, not through a bottle. Update: here’s a little benchmark program, just … Read more

Download binary file from OKHTTP

For what it’s worth, I would recommend response.body().source() from okio (since OkHttp is already supporting it natively) in order to enjoy an easier way to manipulate a large quantity of data that can come when downloading a file. @Override public void onResponse(Call call, Response response) throws IOException { File downloadedFile = new File(context.getCacheDir(), filename); BufferedSink … Read more