File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes IDEs, Version Control and other tools and the fly likes Java InputStream skip() method doesnt work Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "Java InputStream skip() method doesnt work" Watch "Java InputStream skip() method doesnt work" New topic

Java InputStream skip() method doesnt work

jay vas
Ranch Hand

Joined: Aug 30, 2005
Posts: 407
This is a major issue in the Java InputStream API that absolutely has to have some kind of explanation .... I'm wondering if anybody can shed some light on this for me.

Since the late nineties, there has been an open bug in Java's InputStream method for skip(int bytesToSkip). Sometimes, it doesn't actually skip the amount of bytes it recieves as input ? Can anyone explain why it is that skip doesn't always work as it should ?

Here's what the javadoc for InputStream.skip sais ( sais

Skips over and discards n bytes of data from this input stream. The skip method may, for a variety of reasons, end up skipping over some smaller number of bytes, possibly 0. This may result from any of a number of conditions; reaching end of file before n bytes have been skipped is only one possibility. The actual number of bytes skipped is returned. If n is negative, no bytes are skipped.
The skip method of InputStream creates a byte array and then repeatedly reads into it until n bytes have been read or the end of the stream has been reached. Subclasses are encouraged to provide a more efficient implementation of this method.

What gives ? Why is it that an inputstream would ever fail to return the amount of data which it skipped ?

Yes, I know its an interface, and that maybe in designing the interface the API developers decided to accomodate inputstream's which may abstract or hide multiple resources, and which thus would have the possibility of being error prone...... But nevertheless, we just found a bug in some software where the Java FileInputStream was actually skipping inconsistently (i.e. send it 28, and it only skips 8 bytes of a file, even though there are still several 100s of bytes left to go).
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63865

Please don't use code tags for text. It really screws up the formatting of posts.

[Asking smart questions] [About Bear] [Books by Bear]
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
It would be helpful if you provided a link to the issue in the bug tracker. I'm not aware of anyone here at JavaRanch being intimately involved with the JDK development effort, so I'm not sure anyone could say with any amount of certainty what the reasons for not fixing the bug might be.
Gerard Charles

Joined: Jan 21, 2010
Posts: 11
The really old bug report
jay vas
Ranch Hand

Joined: Aug 30, 2005
Posts: 407
Hmmmmm..... Yes, thats certainly the bug report.

Its quite strange isn't it ? I'm dying for some insight here !
Madalina Mutihac

Joined: Mar 03, 2008
Posts: 7
A good video explaining this:
Starts at minute 35. It offers an explanation and solution to go around the problem.
I agree. Here's the link:
subject: Java InputStream skip() method doesnt work
It's not a secret anymore!