2 Replies Latest reply on Aug 27, 2010 3:04 PM by 843790

    Odd behavior of java.nio on diferent Linux version

      Hello everyone!

      I'm new to Java and to these forums. I'm not full time developer, but I wrote small application that stopped working on newer Linux kernel.
      I need your advice before reporting a bug.

      In my application I'm using New I/O to copy segments from one file to new files. The java.​nio.​channels.​FileChannel.transferTo() function works fine on Linux kernel version 2.6.31, but fails to work properly on Linux kernel version 2.6.34.

      What I'm wondering is: is this Linux kernel bug or Java bug?

      Here's the code that I tested under mentioned Linux kernel version, and Java SDK (please read the comments):
      public static void main(String[] args) throws FileNotFoundException, IOException {
              FileInputStream fin = new FileInputStream("input.bin");
              FileOutputStream fout = new FileOutputStream("output.bin");
       * This line copies the whole input file to output file.
              //fout.getChannel().transferFrom(fin.getChannel(), 0, fin.getChannel().size());
       * This line results in zero size output file although output.bin
       * exists and it's size iz larger then second argument (position).
       * Then, what is second argument used for?!
              //fout.getChannel().transferFrom(fin.getChannel(), 16, fin.getChannel().size());
       * This line copies the whole input file to output file.
              //fin.getChannel().transferTo(0, fin.getChannel().size(), fout.getChannel());
       * Linux kernel 2.6.31:
       * This line copies input file starting from offset = 16. The resulting
       * file is 16 bytes smaller then input file.
       * Linux kernel 2.6.34:
       * This line copies input file starting from offset = 16, but after
       * it positions the output file's pointer at offset = 16, so the
       * resulting file has the same size as the input file, but first
       * 16 bytes are zeros.
              //fin.getChannel().transferTo(16, fin.getChannel().size(), fout.getChannel());