xadisk
  1. xadisk
  2. XADISK-85

Java 's FileChannel.transferTo breaks for large number of bytes to be copied, resulting in failure in XADisk's copyFile API.

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.1
    • Fix Version/s: 1.2
    • Component/s: filesystem
    • Labels:
      None

      Description

      Hello,

      Many Thanks to Olaf Eschenbruch for identifying and bringing this issue in front.

      XADisk's copyFile API (see XADiskBasicIOOperation) relies on Java NIO's FileChannel.transferTo method. For large files (around 1.5GB/above), the transferTo method gives error both in Java 5 and Java 6.

      In Java 5, it reports:
      ________________________________________________________________________________________________

      Exception in thread "main" java.io.IOException: Not enough storage is available to process this command
      at sun.nio.ch.FileChannelImpl.map0(Native Method)
      at sun.nio.ch.FileChannelImpl.map(FileChannelImpl.java:742)
      at sun.nio.ch.FileChannelImpl.transferToTrustedChannel(FileChannelImpl.java:448)
      at sun.nio.ch.FileChannelImpl.transferTo(FileChannelImpl.java:521)
      ________________________________________________________________________________________________

      In Java 6, it reports:

      ________________________________________________________________________________________________

      Exception in thread "main" java.io.IOException: Map failed
      at sun.nio.ch.FileChannelImpl.map(FileChannelImpl.java:758)
      at sun.nio.ch.FileChannelImpl.transferToTrustedChannel(FileChannelImpl.java:447)
      at sun.nio.ch.FileChannelImpl.transferTo(FileChannelImpl.java:520)
      ...
      Caused by: java.lang.OutOfMemoryError: Map failed
      at sun.nio.ch.FileChannelImpl.map0(Native Method)
      at sun.nio.ch.FileChannelImpl.map(FileChannelImpl.java:755)
      ... 4 more
      ________________________________________________________________________________________________

      XADisk should implement a workaround for this bug in Java. One possible alternative is to replace:

      num += srcChannel.transferTo(num, contentLength - num, destChannel);

      with

      num += srcChannel.transferTo(num, SOME SMALL CONSTANT (eg 10000), destChannel);

      Thanks,
      Nitin

        Activity

        Hide
        Nitin Verma added a comment -

        Checked-in the changes to trunk.

        Show
        Nitin Verma added a comment - Checked-in the changes to trunk.

          People

          • Assignee:
            Nitin Verma
            Reporter:
            Nitin Verma
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: