tags:

views:

287

answers:

1

When I used BufferedInputStream and I specify a buffer size, Dalvik gives me this warning - Default buffer size used in BufferedInputStream constructor. It would be better to be explicit if an 8k buffer is required.

But right now, my buffer size is already at 8k. What am I doing wrong?

+3  A: 

You're not doing anything wrong. It's just informing you that you chose the version of the BufferedInputStream that doesn't take the size argument. If you use the other one (BufferedInputStream(InputStream in, int size)), then you can specify your own buffer size.

You can choose to ignore the warning if 8KB happens to be exactly what you need, or you can adjust the size with the constructor to tailor it to your needs - as small as possible, as big as necessary.

EboMike
This is correct, but the warning is an indication that the Android framework devs would still prefer that an explicit size request be made rather than relying on the default. From comments in the source, "we want to discourage the use of this constructor". Though, as you say, if an 8K buffer is specified explicitly, there's absolutely no difference in behavior (other than getting no warning logged).
Michael Burr
The log definitely is a difference in behavior, and results in temporary strings being created and such. Just always use the constructor with an explicit size. That's the desired behavior.
hackbod