6516099: InputStream.skipFully(int k) to skip exactly k bytes

Brian Burkhalter brian.burkhalter at oracle.com
Tue Oct 23 22:02:44 UTC 2018

Here is an updated version which hopefully addresses the shortcoming pointed out below:

http://cr.openjdk.java.net/~bpb/6516099/webrev.02/ <http://cr.openjdk.java.net/~bpb/6516099/webrev.02/>

The remaining assumption here is that skip(long) never returns a negative value.



> On Oct 23, 2018, at 11:29 AM, Brian Burkhalter <brian.burkhalter at oracle.com> wrote:
> That is exactly why version .00 of the patch implemented skipNBytes() in a fixed way in terms of read(). I think that there is a good compromise however and I shall update the patch accordingly.
>> On Oct 22, 2018, at 12:55 PM, Brent Christian <brent.christian at oracle.com <mailto:brent.christian at oracle.com>> wrote:
>> 562     public void skipNBytes(long n) throws IOException {
>> 563         if (n > 0 && skip(n) != n) {
>> 564             throw new EOFException("End of stream before enough bytes skipped");
>> 565         }
>> 566     }
>> If an overrided skip() method were to skip < n bytes but not yet be at EOF, which I think the skip() spec allows, then wouldn't skipNBytes() throw an EOFException ?

More information about the core-libs-dev mailing list