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

(fs) File.length() does not match FileChannel.size()

XMLWordPrintable

    • x86
    • windows_2000

      File is updated with two consecutive transferFrom() operations.
      First operation writes 'n' bytes and second operation writes 'm' bytes to underlying file.

      FileChannel.size() returns correct size of underlying file.
      However, File.length() returns 'n' (rather than actual file size).

      This fails on Windows 2000 professional.

      Works fine on Solaris, Windows NT, Linyx, Windows 98.

      --------- part of test code transferFrom.java: xferTest04() ----------
      // FileChannel fcS1, fcS2, fcD ;

      //get read file channel for the file
      fcS1 = Helper.openReadFileChannel(new File(src1FileName));

      //get read file channel for the file
      fcS2 = Helper.openReadFileChannel(new File(src2FileName));


      File file = new File (dstFileName) ;

      // get filechannel for the dst file.
      fcD = Helper.openRWFileChannel(dstFileName) ;

      bytesToWrite = srcData.length ;
      startPosition = 0 ;

      bytesWritten = fcD.transferFrom(fcS1, startPosition, bytesToWrite);

      // verify that first transfer operation is fine.
      System.out.println("bytesWritten=" + bytesWritten);
      System.out.println("fcD.size()=" + fcD.size());

      //fsize = (int) file.length() ;
      //System.out.println("file.length()=" + fsize);

      bytesToWrite = srcData.length / 2 ;
      startPosition = (srcData.length / 2) + (srcData.length / 4) ;

      bytesWritten = fcD.transferFrom(fcS2, startPosition, bytesToWrite);
                  // verify that first transfer operation is fine.
      System.out.println("bytesWritten=" + bytesWritten);
      System.out.println("fcD.size()=" + fcD.size());

      fsize = (int) file.length() ;
      System.out.println("file.length()=" + fsize);

      FileInputStream fis = new FileInputStream (file) ;
      favail = fis.available() ;
      System.out.println("fis.available()=" + favail);

      ------------ results on windows 2000 ------------
      bytesWritten=7868
      fcD.size()=7868
      file.length()=7868
      bytesWritten=3934
      fcD.size()=9835
      file.length()=7868 <<<< should be 9835
      fis.available()=9835

      ----------- result on other platforms -----------
      bytesWritten=7868
      fcD.size()=7868
      file.length()=7868
      bytesWritten=3934
      fcD.size()=9835
      file.length()=9835
      fis.available()=9835
      ----------------------------------

      Merlin Build B-65.

            mmcclosksunw Michael Mccloskey (Inactive)
            hvilekar Harshad Vilekar
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: