• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java InputStream skip() method doesnt work

 
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 (http://java.sun.com/j2se/1.4.2/docs/api/java/io/InputStream.html#skip(long)) 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).
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please don't use code tags for text. It really screws up the formatting of posts.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 45
8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The really old bug report
 
jay vas
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmmmmm..... Yes, thats certainly the bug report.

Its quite strange isn't it ? I'm dying for some insight here !
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A good video explaining this: http://www.infoq.com/presentations/Painful-Java-Puzzlers-and-Bug-Patterns
Starts at minute 35. It offers an explanation and solution to go around the problem.
 
Destiny's powerful hand has made the bed of my future. And this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic