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

java.nio.FileChannel.transferFrom() doesn't work

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P2 P2
    • 1.4.0
    • 1.4.0
    • core-libs
    • beta
    • sparc
    • solaris_7
    • Verified

      transferFrom() doesn't transfer any bytes from source file channel to destination file channel. Also, it returns invalid value -1.

      Same results on Window NT, Solaris and Linux.

      Merlin Beta build B-58.

      ------- part of test code -------------
      String testName = "xferTest01" ;
      byte[] dstData ;
      long fileLength ;
      FileChannel fc1, fc2 ;
      String srcFileName = "src." + testName + partialFileName ;
      String dstFileName = "dst." + testName + partialFileName ;
      byte[] srcData = Helper.getRandomByteArray(MIN_DATA_SIZE, MAX_DATA_SIZE);

      try {
      int bytesWritten ;

      // create a file and write data to the file, then close the file.
      if (! Helper.createFile(srcFileName, srcData)) {
      return TestHelper.testFail(testName + " FAIL: test aborted!");
      }
      //get read file channel for the file
      fc1 = Helper.openReadFileChannel(new File(srcFileName));
      System.out.println("fc1.position=" + fc1.position() + ", fc1.size=" + fc1.size());

      // get filechannel for the dst file.
      fc2 = Helper.openRWFileChannel(dstFileName) ;
      System.out.println("fc2.position=" + fc2.position() + ", fc2.size=" + fc2.size());
      bytesWritten = fc2.transferFrom(fc1, 0, srcData.length);

      if (bytesWritten != srcData.length) { // << fails here
      return TestHelper.testFail(testName + " FAIL: could not write all bytes to file channel " +
      fc2 +": srcData length=" + srcData.length
      + ", written=" + bytesWritten);
      }


      } catch (Exception e) {
      return TestHelper.testFail(testName + " FAIL: Unexpected Exception", e);
      }

      ------- results -------------------
      java FCtransferFrom
      fc1.position=0, fc1.size=5916
      fc2.position=0, fc2.size=0
      TestFailException: xferTest01 FAIL: could not write all bytes to file channel sun.nio.ch.FileChannelImpl@12d342: srcData length=5916, written=-1
              at TestHelper.testFail(TestHelper.java:70)
              at FCtransferFrom.xferTest01(FCtransferFrom.java:156)
      :
      :
      ---------------------------------------

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: