jdk/src/java.base/share/classes/java/nio/channels/package-info.java
changeset 46147 047bdc4d771d
parent 45437 c48b8edad8dd
equal deleted inserted replaced
46146:b3e220a04d3f 46147:047bdc4d771d
    28  * performing I/O operations, such as files and sockets; defines selectors, for
    28  * performing I/O operations, such as files and sockets; defines selectors, for
    29  * multiplexed, non-blocking I/O operations.
    29  * multiplexed, non-blocking I/O operations.
    30  *
    30  *
    31  * <a id="channels"></a>
    31  * <a id="channels"></a>
    32  *
    32  *
    33  * <blockquote><table class="borderless">
    33  * <table class="striped" style="text-align:left; margin-left:2em">
    34  *     <caption style="display:none">Lists channels and their descriptions</caption>
    34  *     <caption style="display:none">Lists channels and their descriptions</caption>
    35  * <tr><th style="text-align:left">Channels</th>
    35  * <thead>
    36  *     <th style="text-align:left">Description</th></tr>
    36  * <tr><th scope="col">Channels</th>
    37  * <tr><td style="vertical-align:top"><i>{@link java.nio.channels.Channel}</i></td>
    37  *     <th scope="col">Description</th></tr>
       
    38  * </thead>
       
    39  * <tbody>
       
    40  * <tr><th scope="row"><i>{@link java.nio.channels.Channel}</i></th>
    38  *     <td>A nexus for I/O operations</td></tr>
    41  *     <td>A nexus for I/O operations</td></tr>
    39  * <tr><td style="vertical-align:top">
    42  * <tr><th scope="row">
    40  *     &nbsp;&nbsp;<i>{@link java.nio.channels.ReadableByteChannel}</i></td>
    43  *     <span style="padding-left:1em"><i>{@link java.nio.channels.ReadableByteChannel}</i></span></th>
    41  *     <td>Can read into a buffer</td></tr>
    44  *     <td>Can read into a buffer</td></tr>
    42  * <tr><td style="vertical-align:top">
    45  * <tr><th scope="row">
    43  *     &nbsp;&nbsp;&nbsp;&nbsp;<i>{@link java.nio.channels.ScatteringByteChannel}&nbsp;&nbsp;</i></td>
    46  *     <span style="padding-left:2em"><i>{@link java.nio.channels.ScatteringByteChannel}</i></span></th>
    44  *     <td>Can read into a sequence of&nbsp;buffers</td></tr>
    47  *     <td>Can read into a sequence of buffers</td></tr>
    45  * <tr><td style="vertical-align:top">
    48  * <tr><th scope="row">
    46  *     &nbsp;&nbsp;<i>{@link java.nio.channels.WritableByteChannel}</i></td>
    49  *     <span style="padding-left:1em"><i>{@link java.nio.channels.WritableByteChannel}</i></span></th>
    47  *     <td>Can write from a buffer</td></tr>
    50  *     <td>Can write from a buffer</td></tr>
    48  * <tr><td style="vertical-align:top">
    51  * <tr><th scope="row">
    49  *     &nbsp;&nbsp;&nbsp;&nbsp;<i>{@link java.nio.channels.GatheringByteChannel}</i></td>
    52  *     <span style="padding-left:2em"><i>{@link java.nio.channels.GatheringByteChannel}</i></span></th>
    50  *     <td>Can write from a sequence of&nbsp;buffers</td></tr>
    53  *     <td>Can write from a sequence of buffers</td></tr>
    51  * <tr><td style="vertical-align:top">
    54  * <tr><th scope="row">
    52  *     &nbsp;&nbsp;<i>{@link java.nio.channels.ByteChannel}</i></td>
    55  *     <span style="padding-left:1em"><i>{@link java.nio.channels.ByteChannel}</i></span></th>
    53  *     <td>Can read/write to/from a&nbsp;buffer</td></tr>
    56  *     <td>Can read/write to/from a buffer</td></tr>
    54  * <tr><td style="vertical-align:top">
    57  * <tr><th scope="row">
    55  *     &nbsp;&nbsp;&nbsp;&nbsp;<i>{@link java.nio.channels.SeekableByteChannel}</i></td>
    58  *     <span style="padding-left:2em"><i>{@link java.nio.channels.SeekableByteChannel}</i></span></th>
    56  *     <td>A {@code ByteChannel} connected to an entity that contains a variable-length
    59  *     <td>A {@code ByteChannel} connected to an entity that contains a variable-length
    57  *         sequence of bytes</td></tr>
    60  *         sequence of bytes</td></tr>
    58  * <tr><td style="vertical-align:top">
    61  * <tr><th scope="row">
    59  *     &nbsp;&nbsp;<i>{@link java.nio.channels.AsynchronousChannel}</i></td>
    62  *     <span style="padding-left:1em"><i>{@link java.nio.channels.AsynchronousChannel}</i></span></th>
    60  *     <td>Supports asynchronous I/O operations.</td></tr>
    63  *     <td>Supports asynchronous I/O operations.</td></tr>
    61  * <tr><td style="vertical-align:top">
    64  * <tr><th scope="row">
    62  *     &nbsp;&nbsp;&nbsp;&nbsp;<i>{@link java.nio.channels.AsynchronousByteChannel}</i></td>
    65  *     <span style="padding-left:2em"><i>{@link java.nio.channels.AsynchronousByteChannel}</i></span></th>
    63  *     <td>Can read and write bytes asynchronously</td></tr>
    66  *     <td>Can read and write bytes asynchronously</td></tr>
    64  * <tr><td style="vertical-align:top">
    67  * <tr><th scope="row">
    65  *     &nbsp;&nbsp;<i>{@link java.nio.channels.NetworkChannel}</i></td>
    68  *     <span style="padding-left:1em"><i>{@link java.nio.channels.NetworkChannel}</i></span></th>
    66  *     <td>A channel to a network socket</td></tr>
    69  *     <td>A channel to a network socket</td></tr>
    67  * <tr><td style="vertical-align:top">
    70  * <tr><th scope="row">
    68  *     &nbsp;&nbsp;&nbsp;&nbsp;<i>{@link java.nio.channels.MulticastChannel}</i></td>
    71  *     <span style="padding-left:2em"><i>{@link java.nio.channels.MulticastChannel}</i></span></th>
    69  *     <td>Can join Internet Protocol (IP) multicast groups</td></tr>
    72  *     <td>Can join Internet Protocol (IP) multicast groups</td></tr>
    70  * <tr><td style="vertical-align:top">{@link java.nio.channels.Channels}</td>
    73  * <tr><th scope="row">{@link java.nio.channels.Channels}</th>
    71  *     <td>Utility methods for channel/stream interoperation</td></tr>
    74  *     <td>Utility methods for channel/stream interoperation</td></tr>
    72  * </table></blockquote>
    75  * </tbody>
       
    76  * </table>
    73  *
    77  *
    74  * <p> A <i>channel</i> represents an open connection to an entity such as a
    78  * <p> A <i>channel</i> represents an open connection to an entity such as a
    75  * hardware device, a file, a network socket, or a program component that is
    79  * hardware device, a file, a network socket, or a program component that is
    76  * capable of performing one or more distinct I/O operations, for example reading
    80  * capable of performing one or more distinct I/O operations, for example reading
    77  * or writing.  As specified in the {@link java.nio.channels.Channel} interface,
    81  * or writing.  As specified in the {@link java.nio.channels.Channel} interface,
   120  * java.io.Reader} can be constructed that uses a given charset to decode bytes
   124  * java.io.Reader} can be constructed that uses a given charset to decode bytes
   121  * from a given readable byte channel, and conversely a {@link java.io.Writer} can
   125  * from a given readable byte channel, and conversely a {@link java.io.Writer} can
   122  * be constructed that uses a given charset to encode characters into bytes and
   126  * be constructed that uses a given charset to encode characters into bytes and
   123  * write them to a given writable byte channel.
   127  * write them to a given writable byte channel.
   124  *
   128  *
   125  * <blockquote><table class="borderless">
   129  * <table class="striped" style="margin-left:2em; text-align:left">
   126  *     <caption style="display:none">
   130  *     <caption style="display:none">
   127  *         Lists file channels and their descriptions</caption>
   131  *         Lists file channels and their descriptions</caption>
   128  * <tr><th style="text-align:left">File channels</th>
   132  * <thead>
   129  *     <th style="text-align:left">Description</th></tr>
   133  * <tr><th scope="col">File channels</th>
   130  * <tr><td style="vertical-align:top">
   134  *     <th scope="col">Description</th></tr>
   131  *     {@link java.nio.channels.FileChannel}</td>
   135  * </thead>
       
   136  * <tbody>
       
   137  * <tr><th scope="row">
       
   138  *     {@link java.nio.channels.FileChannel}</th>
   132  *     <td>Reads, writes, maps, and manipulates files</td></tr>
   139  *     <td>Reads, writes, maps, and manipulates files</td></tr>
   133  * <tr><td style="vertical-align:top">
   140  * <tr><th scope="row">
   134  *     {@link java.nio.channels.FileLock}</td>
   141  *     {@link java.nio.channels.FileLock}</th>
   135  *     <td>A lock on a (region of a) file</td></tr>
   142  *     <td>A lock on a (region of a) file</td></tr>
   136  * <tr><td style="vertical-align:top">
   143  * <tr><th scope="row">
   137  *     {@link java.nio.MappedByteBuffer}&nbsp;&nbsp;</td>
   144  *     {@link java.nio.MappedByteBuffer}</th>
   138  *     <td>A direct byte buffer mapped to a region of a&nbsp;file</td></tr>
   145  *     <td>A direct byte buffer mapped to a region of a file</td></tr>
   139  * </table></blockquote>
   146  * </tbody>
       
   147  * </table>
   140  *
   148  *
   141  * <p> The {@link java.nio.channels.FileChannel} class supports the usual
   149  * <p> The {@link java.nio.channels.FileChannel} class supports the usual
   142  * operations of reading bytes from, and writing bytes to, a channel connected to
   150  * operations of reading bytes from, and writing bytes to, a channel connected to
   143  * a file, as well as those of querying and modifying the current file position
   151  * a file, as well as those of querying and modifying the current file position
   144  * and truncating the file to a specific size.  It defines methods for acquiring
   152  * and truncating the file to a specific size.  It defines methods for acquiring
   154  * java.io.FileOutputStream}, or {@link java.io.RandomAccessFile} to return a
   162  * java.io.FileOutputStream}, or {@link java.io.RandomAccessFile} to return a
   155  * file channel connected to the same underlying file as the {@link java.io}
   163  * file channel connected to the same underlying file as the {@link java.io}
   156  * class.
   164  * class.
   157  *
   165  *
   158  * <a id="multiplex"></a>
   166  * <a id="multiplex"></a>
   159  * <blockquote><table class="borderless">
   167  * <table class="striped" style="margin-left:2em; text-align:left">
   160  *     <caption style="display:none">
   168  *     <caption style="display:none">
   161  *         Lists multiplexed, non-blocking channels and their descriptions</caption>
   169  *         Lists multiplexed, non-blocking channels and their descriptions</caption>
   162  * <tr><th style="text-align:left">Multiplexed, non-blocking I/O</th>
   170  * <thead>
   163  *     <th style="text-align:left">Description</th></tr>
   171  * <tr><th scope="col">Multiplexed, non-blocking I/O</th>
   164  * <tr><td style="vertical-align:top">{@link java.nio.channels.SelectableChannel}</td>
   172  *     <th scope="col">Description</th></tr>
       
   173  * </thead>
       
   174  * <tbody>
       
   175  * <tr><th scope="row">{@link java.nio.channels.SelectableChannel}</th>
   165  *     <td>A channel that can be multiplexed</td></tr>
   176  *     <td>A channel that can be multiplexed</td></tr>
   166  * <tr><td style="vertical-align:top">
   177  * <tr><th scope="row">
   167  *     &nbsp;&nbsp;{@link java.nio.channels.DatagramChannel}</td>
   178  *     <span style="padding-left:2em">{@link java.nio.channels.DatagramChannel}</span></th>
   168  *     <td>A channel to a datagram-oriented socket</td></tr>
   179  *     <td>A channel to a datagram-oriented socket</td></tr>
   169  * <tr><td style="vertical-align:top">
   180  * <tr><th scope="row">
   170  *     &nbsp;&nbsp;{@link java.nio.channels.Pipe.SinkChannel}</td>
   181  *     <span style="padding-left:2em">{@link java.nio.channels.Pipe.SinkChannel}</span></th>
   171  *     <td>The write end of a pipe</td></tr>
   182  *     <td>The write end of a pipe</td></tr>
   172  * <tr><td style="vertical-align:top">
   183  * <tr><th scope="row">
   173  *     &nbsp;&nbsp;{@link java.nio.channels.Pipe.SourceChannel}</td>
   184  *     <span style="padding-left:2em">{@link java.nio.channels.Pipe.SourceChannel}</span></th>
   174  *     <td>The read end of a pipe</td></tr>
   185  *     <td>The read end of a pipe</td></tr>
   175  * <tr><td style="vertical-align:top">
   186  * <tr><th scope="row">
   176  *     &nbsp;&nbsp;{@link java.nio.channels.ServerSocketChannel}&nbsp;&nbsp;</td>
   187  *     <span style="padding-left:2em">{@link java.nio.channels.ServerSocketChannel}</span></th>
   177  *     <td>A channel to a stream-oriented listening socket</td></tr>
   188  *     <td>A channel to a stream-oriented listening socket</td></tr>
   178  * <tr><td style="vertical-align:top">
   189  * <tr><th scope="row">
   179  *     &nbsp;&nbsp;{@link java.nio.channels.SocketChannel}</td>
   190  *     <span style="padding-left:2em">{@link java.nio.channels.SocketChannel}</span></th>
   180  *     <td>A channel for a stream-oriented connecting socket</td></tr>
   191  *     <td>A channel for a stream-oriented connecting socket</td></tr>
   181  * <tr><td style="vertical-align:top">{@link java.nio.channels.Selector}</td>
   192  * <tr><th scope="row">{@link java.nio.channels.Selector}</th>
   182  *     <td>A multiplexor of selectable channels</td></tr>
   193  *     <td>A multiplexor of selectable channels</td></tr>
   183  * <tr><td style="vertical-align:top">{@link java.nio.channels.SelectionKey}</td>
   194  * <tr><th scope="row">{@link java.nio.channels.SelectionKey}</th>
   184  *     <td>A token representing the registration <br> of a channel
   195  *     <td>A token representing the registration of a channel
   185  *     with&nbsp;a&nbsp;selector</td></tr>
   196  *     with a selector</td></tr>
   186  * <tr><td style="vertical-align:top">{@link java.nio.channels.Pipe}</td>
   197  * <tr><th scope="row">{@link java.nio.channels.Pipe}</th>
   187  *     <td>Two channels that form a unidirectional&nbsp;pipe</td></tr>
   198  *     <td>Two channels that form a unidirectional pipe</td></tr>
   188  * </table></blockquote>
   199  * </tbody>
       
   200  * </table>
   189  *
   201  *
   190  * <p> Multiplexed, non-blocking I/O, which is much more scalable than
   202  * <p> Multiplexed, non-blocking I/O, which is much more scalable than
   191  * thread-oriented, blocking I/O, is provided by <i>selectors</i>, <i>selectable
   203  * thread-oriented, blocking I/O, is provided by <i>selectors</i>, <i>selectable
   192  * channels</i>, and <i>selection keys</i>.
   204  * channels</i>, and <i>selection keys</i>.
   193  *
   205  *
   249  * directly; custom channel classes should extend the appropriate {@link
   261  * directly; custom channel classes should extend the appropriate {@link
   250  * java.nio.channels.SelectableChannel} subclasses defined in this package.
   262  * java.nio.channels.SelectableChannel} subclasses defined in this package.
   251  *
   263  *
   252  * <a id="async"></a>
   264  * <a id="async"></a>
   253  *
   265  *
   254  * <blockquote><table class="borderless">
   266  * <table class="striped" style="padding-left:2em; text-align:left">
   255  *     <caption style="display:none">
   267  *     <caption style="display:none">
   256  *         Lists asynchronous channels and their descriptions</caption>
   268  *         Lists asynchronous channels and their descriptions</caption>
   257  * <tr><th style="text-align:left">
   269  * <thead>
   258  *     Asynchronous I/O</th><th style="text-align:left">Description</th></tr>
   270  * <tr><th scope="col">Asynchronous I/O</th>
   259  * <tr><td style="vertical-align:top">
   271  *     <th scope="col">Description</th></tr>
   260  *     {@link java.nio.channels.AsynchronousFileChannel}</td>
   272  * </thead>
       
   273  * <tbody>
       
   274  * <tr><th scope="row">
       
   275  *     {@link java.nio.channels.AsynchronousFileChannel}</th>
   261  *     <td>An asynchronous channel for reading, writing, and manipulating a file</td></tr>
   276  *     <td>An asynchronous channel for reading, writing, and manipulating a file</td></tr>
   262  * <tr><td style="vertical-align:top">
   277  * <tr><th scope="row">
   263  *     {@link java.nio.channels.AsynchronousSocketChannel}</td>
   278  *     {@link java.nio.channels.AsynchronousSocketChannel}</th>
   264  *     <td>An asynchronous channel to a stream-oriented connecting socket</td></tr>
   279  *     <td>An asynchronous channel to a stream-oriented connecting socket</td></tr>
   265  * <tr><td style="vertical-align:top">
   280  * <tr><th scope="row">
   266  *     {@link java.nio.channels.AsynchronousServerSocketChannel}&nbsp;&nbsp;</td>
   281  *     {@link java.nio.channels.AsynchronousServerSocketChannel}</th>
   267  *     <td>An asynchronous channel to a stream-oriented listening socket</td></tr>
   282  *     <td>An asynchronous channel to a stream-oriented listening socket</td></tr>
   268  * <tr><td style="vertical-align:top">
   283  * <tr><th scope="row">
   269  *     {@link java.nio.channels.CompletionHandler}</td>
   284  *     {@link java.nio.channels.CompletionHandler}</th>
   270  *     <td>A handler for consuming the result of an asynchronous operation</td></tr>
   285  *     <td>A handler for consuming the result of an asynchronous operation</td></tr>
   271  * <tr><td style="vertical-align:top">
   286  * <tr><th scope="row">
   272  *     {@link java.nio.channels.AsynchronousChannelGroup}</td>
   287  *     {@link java.nio.channels.AsynchronousChannelGroup}</th>
   273  *     <td>A grouping of asynchronous channels for the purpose of resource sharing</td></tr>
   288  *     <td>A grouping of asynchronous channels for the purpose of resource sharing</td></tr>
   274  * </table></blockquote>
   289  * </tbody>
       
   290  * </table>
   275  *
   291  *
   276  * <p> {@link java.nio.channels.AsynchronousChannel Asynchronous channels} are a
   292  * <p> {@link java.nio.channels.AsynchronousChannel Asynchronous channels} are a
   277  * special type of channel capable of asynchronous I/O operations. Asynchronous
   293  * special type of channel capable of asynchronous I/O operations. Asynchronous
   278  * channels are non-blocking and define methods to initiate asynchronous
   294  * channels are non-blocking and define methods to initiate asynchronous
   279  * operations, returning a {@link java.util.concurrent.Future} representing the
   295  * operations, returning a {@link java.util.concurrent.Future} representing the