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

AsynchronousFileChannel should implement AsynchronousByteChannel directly

    XMLWordPrintable

Details

    • generic
    • generic

    Description

      ADDITIONAL SYSTEM INFORMATION :
      Windows 10 Java 17.0.4.1

      A DESCRIPTION OF THE PROBLEM :
      Not a major issue but it will enhance usability

      The AsynchronousFileChannel[https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/nio/channels/AsynchronousFileChannel.html] class has 4 methods for I/O 2 for reading and 2 for writing

      abstract Future<Integer> read(ByteBuffer dst, long position)
      abstract <A> void read(ByteBuffer dst, long position, A attachment, CompletionHandler<Integer,? super A> handler)
      abstract Future<Integer> write(ByteBuffer src, long position)
      abstract <A> void write(ByteBuffer src, long position, A attachment, CompletionHandler<Integer,? super A> handler)

      These 4 methods are also part of the AsynchronousByteChannel interface [https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/nio/channels/AsynchronousByteChannel.html]

      Hence making AsynchronousFileChannel implement this interface rather than AsynchronousChannel directly would be more logical as AsynchronousByteChannel extends AsynchronousChannel anyway so developers don't have to change code anywhere

      Another advantage of doing this is that the Channels class[https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/nio/channels/Channels.html] could then work with the AsynchronousFileChannel using its 2 methods

      static InputStream newInputStream(AsynchronousByteChannel ch)
      static OutputStream newOutputStream(AsynchronousByteChannel ch)

      It would be an added bonus



      Attachments

        Activity

          People

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: