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

(fs) FileChannel.transferTo does not throw ClosedChannelException

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      hopper
    • CPU:
      sparc
    • OS:
      solaris_2.6
    • Verification:
      Verified

      Description



      Name: auR10023 Date: 03/28/2002


      java.nio.channels.FileChannel.transferTo(long, long,
      WritableByteChannel) method does not throw ClosedChannelException with
      closed WritableByteChannel. Here is the example:

      ----test.java----
      import java.nio.*;
      import java.nio.channels.*;
      import java.io.*;

      public class test {
          public static void main (String args []) {
              FileChannel channel = null;
              try {
                  FileOutputStream os = (new FileOutputStream("aaa"));
                  os.write(new byte [] {1,2,3,4,5});
                  os.close();
                  channel = (new FileInputStream("aaa")).getChannel();
              } catch (IOException e) {
                  System.out.println("Unexpected IOException");
              }
              ByteArrayOutputStream ostr = new ByteArrayOutputStream(4);
              WritableByteChannel wch = Channels.newChannel(ostr);
              try {
                  wch.close();
              } catch (IOException e) {
                  System.out.println(e);
              }
              try {
                  channel.transferTo(0, 2, wch);
                  System.out.println("ClosedChannelException expected");
              } catch (Throwable e) {
                  System.out.println(e);
              }
          }
      }

      #java -version
      java version "1.4.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
      Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)

      #java test
      ClosedChannelException expected

      ======================================================================

        Attachments

          Activity

            People

            Assignee:
            mmcclosksunw Michael Mccloskey (Inactive)
            Reporter:
            avusunw Avu Avu (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: