JDK-6176772 : (spec) FileInputStream.available - return value documentation is misleading
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version: 5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2004-10-11
  • Updated: 2010-07-29
  • Resolved: 2005-05-20
Related Reports
Duplicate :  
Description
A DESCRIPTION OF THE PROBLEM :
Although the documentation is strictly speaking correct, it is being widely interpreted as meaning that the value returned is the number of bytes remaining to be read in the file. In particular, if no bytes have yet been read from the stream, it is being taken to be the number of bytes in the file.

This seems to be based on an assumption that file reads cannot block. This may be true in current OS implementations (though indeed may not be), but clearly future OS implementations may provide better support, particularly in the context of network file systems.

The assumption must in any case be incorrect for files that are of size greater than Integer.MAX_INT bytes (approx 2Gb).



EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Returns the number of bytes that can be read from this file input stream without blocking.

It should be noted that the value returned is not necessarily the number of bytes remaning to be read from the stream, even if the stream is open to an ordinary file on a local disk.
ACTUAL -
Returns the number of bytes that can be read from this file input stream without blocking.

URL OF FAULTY DOCUMENTATION :
http://java.sun.com/j2se/1.5.0/docs/api/java/io/FileInputStream.html#available()
###@###.### 10/11/04 04:53 GMT

Comments
EVALUATION Similar changes may be necessary in all java.io classes which extend InputStream. ###@###.### 10/25/04 19:33 GMT Duplicated to 4711604 ###@###.### 2005-05-20 11:46:04 GMT
25-10-2004