Some character sets have a preample - for example utf-16 which has a BOM indicator. ReaderInputStream does not handle this because it restarts the stream for each block read in: in readBytes: if (n > 0) { slack = new String(buf, 0, n).getBytes(encoding); begin = 0; } The String.getBytes does the encoding, but it can be called a number of times.
Unfortunately the bug is still relevant, and it does impact users by corrupting the stream. Here's unexpected file corruption in Gradle: https://github.com/gradle/gradle/issues/14134 I suggest to replace Ant's ReaderInputStream with the implementation from commons-io. What do you think?
We've implemented Vladimir's suggestion for 1.10.9.