-
Bug
-
Resolution: Fixed
-
P2
-
1.1, 1.1.1
-
1.1.1
-
generic, sparc
-
generic, solaris_2.5.1
-
Not verified
RandomAccessFile.readFully() hangs when you attempt to read n bytes and less than n bytes remain in the file. The Java Application Programming Interface says that an EOFException should be thrown if end-of-file is reached while attempting to read from this file.
Test case output:
sumba 85 =>java RAFTest
Length of file: 4
Contents of file: >0123<
readByte: 0
readByte: 1
Request 3 more bytes from the raf: readFully(0,3)...
Test case:
import java.io.*;
class RAFTest {
public static void main(String[] args) {
try {
RandomAccessFile raf = new RandomAccessFile("test_raf", "rw");
// Write 0123 into the raf.
byte[] b = {0,1,2,3};
raf.write(b);
raf.close();
// Print contents of the file.
raf = new RandomAccessFile("test_raf", "r");
byte[] b4 = {9,9,9,9};
raf.read(b4);
System.err.println("Length of file: " +raf.length());
System.err.println("Contents of file: >" +b4[0]+b4[1]+b4[2]+b4[3]+ "<");
raf.close();
raf = new RandomAccessFile("test_raf", "r");
byte[] b3 = {9,9,9};
int off = 0;
int len = 3;
// Read first two bytes (01)
System.err.println("readByte: " +raf.readByte());
System.err.println("readByte: " +raf.readByte());
// Attempt to read 3 bytes from the raf and put them into
// b3 starting at b3[0]. Note: There are only two bytes
// left in the raf.
//
System.err.println("Request " +len+ " more bytes from the raf: readFully(" +off+ "," +len+ ")...");
raf.readFully(b3, off, len);
System.err.println("Result: >" + b3[0] + b3[1] + b3[2] + "<");
}
catch (IOException e) {
System.err.println(e);
}
}
}
Test case output:
sumba 85 =>java RAFTest
Length of file: 4
Contents of file: >0123<
readByte: 0
readByte: 1
Request 3 more bytes from the raf: readFully(0,3)...
Test case:
import java.io.*;
class RAFTest {
public static void main(String[] args) {
try {
RandomAccessFile raf = new RandomAccessFile("test_raf", "rw");
// Write 0123 into the raf.
byte[] b = {0,1,2,3};
raf.write(b);
raf.close();
// Print contents of the file.
raf = new RandomAccessFile("test_raf", "r");
byte[] b4 = {9,9,9,9};
raf.read(b4);
System.err.println("Length of file: " +raf.length());
System.err.println("Contents of file: >" +b4[0]+b4[1]+b4[2]+b4[3]+ "<");
raf.close();
raf = new RandomAccessFile("test_raf", "r");
byte[] b3 = {9,9,9};
int off = 0;
int len = 3;
// Read first two bytes (01)
System.err.println("readByte: " +raf.readByte());
System.err.println("readByte: " +raf.readByte());
// Attempt to read 3 bytes from the raf and put them into
// b3 starting at b3[0]. Note: There are only two bytes
// left in the raf.
//
System.err.println("Request " +len+ " more bytes from the raf: readFully(" +off+ "," +len+ ")...");
raf.readFully(b3, off, len);
System.err.println("Result: >" + b3[0] + b3[1] + b3[2] + "<");
}
catch (IOException e) {
System.err.println(e);
}
}
}
- duplicates
-
JDK-4067088 java.io.RandomAccessFile.read returns 0 instead of -1 on EOF
- Closed
- relates to
-
JDK-4156663 (1.1.7) Regression test failure: io\RandomAccessFile\EOF.java
- Resolved