Search code examples
javaskipbufferedinputstream

skip method in Class BufferedInputStream is not skipping exactly n bytes


        int a  = bis.available();
        System.out.println("*****"+a);
        bis.skip(10000);
        a  = bis.available();
        System.out.println("*****"+a);
        bis.skip(10000);
        a  = bis.available();
        System.out.println("*****"+a);

Output:

*****369608
*****361424
*****351424

When I use skip, if I try to skip 10000, it will only skip 8184 bytes. If I do that again, it will work properly this time.


Solution

  • This is working as specified. From the spec:

    The skip method may, for a variety of reasons, end up skipping over some smaller number of bytes, possibly 0. [...] The actual number of bytes skipped is returned.