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

java.io.RandomAccessFile.readInt() does not throw EOFException

    XMLWordPrintable

Details

    • sparc
    • solaris_2.5.1

    Description



      Name: akC57697 Date: 07/14/98



         The java.io.RandomAccessFile.readInt() does not throw EOFException and hangs
       if this file reaches the end before reading four bytes.
       
       The documentation says:
      "
      public final native int readInt() throws IOException

       Reads a signed 32-bit integer from this file. This method reads 4
       bytes from the file, starting at the current file pointer.
        ....
       This method blocks until the four bytes are read, the end of the
       stream is detected, or an exception is thrown.

       @return the next four bytes of this file, interpreted as an
                   int.
       @exception EOFException if this file reaches the end before reading
                   ^^^^^^^^^^^^^^^^^^^
                     four bytes.
       @exception IOException if an I/O error occurs.
      "
       
       
      The example:
      ------------------------------8-<--------------------------------------------
      import java.io.*;

      class Test {
        public static void main(String[] argv) {
        
        try {
         FileOutputStream fos = new FileOutputStream("File.dat");
         fos.write(1);
         fos.close();
         
         RandomAccessFile raf = new RandomAccessFile("File.dat","rw");

         try {
          System.out.println("Read int ...");
          int i=raf.readInt();
          System.out.println("No EOFException");
          System.exit(1);
         } catch (IOException ex) {
          System.out.println("OKAY");
          System.exit(0);
         }
         
         
        } catch (Exception e) {
          System.out.println("Unexpected:"+e);
          System.exit(0);
        }
          
         }
      }
      ---------------------------->-8----------------------------------------------
      Output:
      Read int ...
      ^C
      java full version "JDK-1.2fcs-B"

      ======================================================================

      Attachments

        Issue Links

          Activity

            People

              bgomessunw Benedict Gomes (Inactive)
              akuzminorcl Alexander Kuzmin (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: