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

FileInputStream.skip( long ) does not stop at EOF

XMLWordPrintable

    • tiger
    • generic, x86
    • generic, windows_nt, windows_2000

      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)
      ======================================================================

            mmcclosksunw Michael Mccloskey (Inactive)
            kryansunw Kevin Ryan (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: