Name: saC57035 Date: 10/13/98
The FileInputStream.skip(n) method throws IOException if n is negative.
This behavior:
a) violates the general contract of the skip method documented in
the InputStream javadoc comments (".. If n is negative,
no bytes are skipped.")
b) works inconsistently with all other InputStream subclasses. All those
classes return 0 and do nothing if skip(negative) is called.
Here is the test example:
----------------------------------------------------
import java.io.*;
public class Test {
public static void main(String [] args) {
FileInputStream f=null;
try {
f = new FileInputStream("Test.java");
} catch (FileNotFoundException e) {
System.out.println("File not found: Test.java");
System.exit(0);
}
try {
if (f.skip(-10) == 0)
System.out.println("OKAY");
else
System.out.println("FAILED");
} catch (Throwable e) {
System.out.println("FAILED: "+e+" thrown");
e.printStackTrace();
}
}
}
----------------------------------------------------
Here is the test output:
----------------------------------------------------
95% java Test
FAILED: java.io.IOException thrown
java.io.IOException
at Test.main(Test.java:13)
----------------------------------------------------
======================================================================
The FileInputStream.skip(n) method throws IOException if n is negative.
This behavior:
a) violates the general contract of the skip method documented in
the InputStream javadoc comments (".. If n is negative,
no bytes are skipped.")
b) works inconsistently with all other InputStream subclasses. All those
classes return 0 and do nothing if skip(negative) is called.
Here is the test example:
----------------------------------------------------
import java.io.*;
public class Test {
public static void main(String [] args) {
FileInputStream f=null;
try {
f = new FileInputStream("Test.java");
} catch (FileNotFoundException e) {
System.out.println("File not found: Test.java");
System.exit(0);
}
try {
if (f.skip(-10) == 0)
System.out.println("OKAY");
else
System.out.println("FAILED");
} catch (Throwable e) {
System.out.println("FAILED: "+e+" thrown");
e.printStackTrace();
}
}
}
----------------------------------------------------
Here is the test output:
----------------------------------------------------
95% java Test
FAILED: java.io.IOException thrown
java.io.IOException
at Test.main(Test.java:13)
----------------------------------------------------
======================================================================
- relates to
-
JDK-4178064 java.io.FileInputStream.skip returns incorrect result at EOF
-
- Closed
-
-
JDK-6294974 FileInputStream.skip(long) does not stop at EOF
-
- Closed
-