Name: krC82822 Date: 05/03/2001
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)
When the skip(long) method is used from any position in the stream with a skip
value that is larger than the available bytes in the stream, the skip method
skips beyond EOF and returns the same value that was given to it.
See code below.
There are several related bugs on the Bug Parade.
However, # 4178064, the closest match,
appears to restrict the problem to [what happens]
once the EOF has already been reached.
The scope of the problem is larger than that.
Also of note: the workaround for that bug
does not help in the situation that I demonstrate.
I think it would be helpful for others to have access to
the workaround I have provided.
========================================================
import java.io.*;
public class TestFileInputStream
{
public static void main(String argv[])
{
try
{
//Open a FileInputStream for a "small" file
FileInputStream f = new FileInputStream("c:\\Test.txt");
//Try skipping way past the end of file.
//This call should return the number of bytes in the file
//but instead returns 500000, which according to the contract
//for InputStream, may/should return less if the end of file is
//reached
long skipped = f.skip(500000);
System.out.println("Skipped " + skipped + " bytes");
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
=================================================
(Review ID: 123668)
======================================================================
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)
When the skip(long) method is used from any position in the stream with a skip
value that is larger than the available bytes in the stream, the skip method
skips beyond EOF and returns the same value that was given to it.
See code below.
There are several related bugs on the Bug Parade.
However, # 4178064, the closest match,
appears to restrict the problem to [what happens]
once the EOF has already been reached.
The scope of the problem is larger than that.
Also of note: the workaround for that bug
does not help in the situation that I demonstrate.
I think it would be helpful for others to have access to
the workaround I have provided.
========================================================
import java.io.*;
public class TestFileInputStream
{
public static void main(String argv[])
{
try
{
//Open a FileInputStream for a "small" file
FileInputStream f = new FileInputStream("c:\\Test.txt");
//Try skipping way past the end of file.
//This call should return the number of bytes in the file
//but instead returns 500000, which according to the contract
//for InputStream, may/should return less if the end of file is
//reached
long skipped = f.skip(500000);
System.out.println("Skipped " + skipped + " bytes");
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
=================================================
(Review ID: 123668)
======================================================================
- duplicates
-
JDK-4178064 java.io.FileInputStream.skip returns incorrect result at EOF
-
- Closed
-
-
JDK-6294974 FileInputStream.skip(long) does not stop at EOF
-
- Closed
-