Style-nit: Please don't make unrelated changes if you can avoid it.  There isn't a good reason to switch Math.min() to min() while also trying to fix the code to not materialize all data in a byte[].

If this change is worthwhile (and it may be for readability reasons), please make it a separate commit.