Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4017497

java.io.RandomAccessFile.readFully() hangs on EOF

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      1.1.1
    • CPU:
      generic, sparc
    • OS:
      generic, solaris_2.5.1
    • Verification:
      Not verified

      Description

      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);
      }
         }
      }

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              djbrown David Brown (Inactive)
              Reporter:
              duke J. Duke (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: