`
Donald_Draper
  • 浏览: 982343 次
社区版块
存档分类
最新评论

ByteChannel,分散聚集通道接口的定义(SocketChannel)

    博客分类:
  • NIO
阅读更多
Channel接口定义:http://donald-draper.iteye.com/blog/2369111
AbstractInterruptibleChannel接口定义:http://donald-draper.iteye.com/blog/2369238
SelectableChannel接口定义:http://donald-draper.iteye.com/blog/2369317
SelectionKey定义:http://donald-draper.iteye.com/blog/2369499
SelectorProvider定义:http://donald-draper.iteye.com/blog/2369615
AbstractSelectableChannel定义:http://donald-draper.iteye.com/blog/2369742
NetworkChannel接口定义:http://donald-draper.iteye.com/blog/2369773
ServerSocketChannel定义:http://donald-draper.iteye.com/blog/2369836
ServerSocketChannelImpl解析:http://donald-draper.iteye.com/blog/2370912
Selector定义:http://donald-draper.iteye.com/blog/2370015
AbstractSelector定义:http://donald-draper.iteye.com/blog/2370138
SelectorImpl分析 :http://donald-draper.iteye.com/blog/2370519
WindowsSelectorImpl解析一(FdMap,PollArrayWrapper):
http://donald-draper.iteye.com/blog/2370811
WindowsSelectorImpl解析二(选择操作,通道注册,通道反注册,选择器关闭等):
http://donald-draper.iteye.com/blog/2370862
在前面的文章中我们看了选择器(选择操作,更新通道就绪操作事件)和
ServerSocketChannle(绑定地址,接受连接),接下来的文章我们SocketChannel,
SocketChannel主要完成连接,读写通道,今天看一下SocketChannel的字节通道,
分散读和聚集写通道接口的定义。
//SocketChannel
public abstract class SocketChannel
    extends AbstractSelectableChannel
    implements ByteChannel, ScatteringByteChannel, GatheringByteChannel, NetworkChannel
{}

//ByteChannel
package java.nio.channels;
import java.io.IOException;
/**
 * A channel that can read and write bytes.  This interface simply unifies
 * {@link ReadableByteChannel} and {@link WritableByteChannel}; it does not
 * specify any new operations.
 *ByteChannel可以读写字节流,这个接口统一了ReadableByteChannel和WritableByteChannel
 ;没有新的操作
 * @author Mark Reinhold
 * @author JSR-51 Expert Group
 * @since 1.4
 */
public interface ByteChannel
    extends ReadableByteChannel, WritableByteChannel
{
}
//ReadableByteChannel
package java.nio.channels;

import java.io.IOException;
import java.nio.ByteBuffer;


/**
 * A channel that can read bytes.
 *ReadableByteChannel可以从通道中读取字节
 *  Only one read operation upon a readable channel may be in progress at
 * any given time.  If one thread initiates a read operation upon a channel
 * then any other thread that attempts to initiate another read operation will
 * block until the first operation is complete.  Whether or not other kinds of
 * I/O operations may proceed concurrently with a read operation depends upon
 * the type of the channel. 

 *在可读的通道中,一个进程只能有一个读操作。如果当前线程正在读通道,其他尝试
 读通道的线程,必须等待正在读痛的线程完成。
 *
 * @author Mark Reinhold
 * @author JSR-51 Expert Group
 * @since 1.4
 */

public interface ReadableByteChannel extends Channel {

    /**
     * Reads a sequence of bytes from this channel into the given buffer.
     *从通道中读取字节序列,写到缓存中。
     *  An attempt is made to read up to <i>r</i> bytes from the channel,
     * where <i>r</i> is the number of bytes remaining in the buffer, that is,
     * <tt>dst.remaining()</tt>, at the moment this method is invoked.
     *只能读取缓冲剩余空间容量的字节序列到缓存。
     * <p> Suppose that a byte sequence of length <i>n</i> is read, where
     * <tt>0</tt> <tt><=</tt> <i>n</i> <tt><=</tt> <i>r</i>.
     * This byte sequence will be transferred into the buffer so that the first
     * byte in the sequence is at index <i>p</i> and the last byte is at index
     * <i>p</i> <tt>+</tt> <i>n</i> <tt>-</tt> <tt>1</tt>,
     * where <i>p</i> is the buffer's position at the moment this method is
     * invoked.  Upon return the buffer's position will be equal to
     * <i>p</i> <tt>+</tt> <i>n</i>; its limit will not have changed.
     *
     * <p> A read operation might not fill the buffer, and in fact it might not
     * read any bytes at all.  Whether or not it does so depends upon the
     * nature and state of the channel.  A socket channel in non-blocking mode,
     * for example, cannot read any more bytes than are immediately available
     * from the socket's input buffer; similarly, a file channel cannot read
     * any more bytes than remain in the file.  It is guaranteed, however, that
     * if a channel is in blocking mode and there is at least one byte
     * remaining in the buffer then this method will block until at least one
     * byte is read.
     *一个读操作也许不能填充缓存,实际也许没有读取任何字节。是否能够填充和读取字节,
     依赖于通道的状态。一个非阻塞的通道不能读取大于socket输入缓冲区容量的字节数;相似地,
     一个文件通道不能读取大于文件字节大小的字节。如果通道为阻塞模式,则至少有一个字节在通道的socket
     输入缓存区中可用,如果没有read方法阻塞到至少有一个字节可用。
     * <p> This method may be invoked at any time.  If another thread has
     * already initiated a read operation upon this channel, however, then an
     * invocation of this method will block until the first operation is
     * complete. 

     *此方法可以在任何时候调用。如果其他线程已经执行一个读操作,则当前读操作阻塞到其他
     线程执行完读操作。
     * @param  dst
     *         The buffer into which bytes are to be transferred
     *
     * @return  The number of bytes read, possibly zero, or <tt>-1</tt> if the
     *          channel has reached end-of-stream
     *
     * @throws  NonReadableChannelException
     *          If this channel was not opened for reading
     *
     * @throws  ClosedChannelException
     *          If this channel is closed
     *
     * @throws  AsynchronousCloseException
     *          If another thread closes this channel
     *          while the read operation is in progress
     *
     * @throws  ClosedByInterruptException
     *          If another thread interrupts the current thread
     *          while the read operation is in progress, thereby
     *          closing the channel and setting the current thread's
     *          interrupt status
     *
     * @throws  IOException
     *          If some other I/O error occurs
     */
    public int read(ByteBuffer dst) throws IOException;
}
//WritableByteChannel
package java.nio.channels;

import java.io.IOException;
import java.nio.ByteBuffer;


/**
 * A channel that can write bytes.
 *WritableByteChannel可以写字节流的通道
 *  Only one write operation upon a writable channel may be in progress at
 * any given time.  If one thread initiates a write operation upon a channel
 * then any other thread that attempts to initiate another write operation will
 * block until the first operation is complete.  Whether or not other kinds of
 * I/O operations may proceed concurrently with a write operation depends upon
 * the type of the channel. 

 *一个可写的通道在一个进程中同时只能有一个写操作。当一个线程在写通道,其他尝试写
 通道的线程将会阻塞,直至正在写的线程完成。
 通道。
 *
 * @author Mark Reinhold
 * @author JSR-51 Expert Group
 * @since 1.4
 */

public interface WritableByteChannel
    extends Channel
{

    /**
     * Writes a sequence of bytes to this channel from the given buffer.
     *从通道读取字节流,写到缓冲区。
     *  An attempt is made to write up to <i>r</i> bytes to the channel,
     * where <i>r</i> is the number of bytes remaining in the buffer, that is,
     * <tt>src.remaining()</tt>, at the moment this method is invoked.
     *具体能写多少字节流,依赖于缓冲区的当前可用大小
     * <p> Suppose that a byte sequence of length <i>n</i> is written, where
     * <tt>0</tt> <tt><=</tt> <i>n</i> <tt><=</tt> <i>r</i>.
     * This byte sequence will be transferred from the buffer starting at index
     * <i>p</i>, where <i>p</i> is the buffer's position at the moment this
     * method is invoked; the index of the last byte written will be
     * <i>p</i> <tt>+</tt> <i>n</i> <tt>-</tt> <tt>1</tt>.
     * Upon return the buffer's position will be equal to
     * <i>p</i> <tt>+</tt> <i>n</i>; its limit will not have changed.
     *
     * <p> Unless otherwise specified, a write operation will return only after
     * writing all of the <i>r</i> requested bytes.  Some types of channels,
     * depending upon their state, may write only some of the bytes or possibly
     * none at all.  A socket channel in non-blocking mode, for example, cannot
     * write any more bytes than are free in the socket's output buffer.
     *一个写操作在写r个请求字节后返回。其他一些类型通道,要依赖于他们的状态,也许
     只写一些字节,也可能没有。一个非阻塞模式的,不能写比socket输出缓冲区实际容量多的字节。
     * <p> This method may be invoked at any time.  If another thread has
     * already initiated a write operation upon this channel, however, then an
     * invocation of this method will block until the first operation is
     * complete. 

     *当一个线程在写通道,其他尝试写通道的线程将会阻塞,直至正在写的线程完成。
     * @param  src
     *         The buffer from which bytes are to be retrieved
     *
     * @return The number of bytes written, possibly zero
     *
     * @throws  NonWritableChannelException
     *          If this channel was not opened for writing
     *
     * @throws  ClosedChannelException
     *          If this channel is closed
     *
     * @throws  AsynchronousCloseException
     *          If another thread closes this channel
     *          while the write operation is in progress
     *
     * @throws  ClosedByInterruptException
     *          If another thread interrupts the current thread
     *          while the write operation is in progress, thereby
     *          closing the channel and setting the current thread's
     *          interrupt status
     *
     * @throws  IOException
     *          If some other I/O error occurs
     */
    public int write(ByteBuffer src) throws IOException;
}
//ScatteringByteChannel
package java.nio.channels;

import java.io.IOException;
import java.nio.ByteBuffer;
/**
 * A channel that can read bytes into a sequence of buffers.
 *ScatteringByteChannel可以从通道读取字节流,写到一组缓冲区中。
 *  A <i>scattering</i> read operation reads, in a single invocation, a
 * sequence of bytes into one or more of a given sequence of buffers.
 * Scattering reads are often useful when implementing network protocols or
 * file formats that, for example, group data into segments consisting of one
 * or more fixed-length headers followed by a variable-length body.  Similar
 * <i>gathering</i> write operations are defined in the {@link
 * GatheringByteChannel} interface.  

 *scattering读操作,从通道读取字节序列,写到一组缓冲区中。分散读操作用于网络协议和文件格式化
 场景中国,比如,一个网络协议可能包括一个或多个固定长度的头部,跟着一个可变长度的body。
 相似的聚集写操作在GatheringByteChannel接口中定义。
 *
 * @author Mark Reinhold
 * @author JSR-51 Expert Group
 * @since 1.4
 */

public interface ScatteringByteChannel
    extends ReadableByteChannel
{

    /**
     * Reads a sequence of bytes from this channel into a subsequence of the
     * given buffers.
     *从通道读写字节流,写到一组缓冲区中
     *  An invocation of this method attempts to read up to <i>r</i> bytes
     * from this channel, where <i>r</i> is the total number of bytes remaining
     * the specified subsequence of the given buffer array, that is,
     *此方法调用时,将会从通道读取所有缓冲区可用空间之和大小的字节
     * <blockquote><pre>
     * dsts[offset].remaining()
     *     + dsts[offset+1].remaining()
     *     + ... + dsts[offset+length-1].remaining()</pre></blockquote>
     *
     * at the moment that this method is invoked.
     *
     * <p> Suppose that a byte sequence of length <i>n</i> is read, where
     * <tt>0</tt> <tt><=</tt> <i>n</i> <tt><=</tt> <i>r</i>.
     * Up to the first <tt>dsts[offset].remaining()</tt> bytes of this sequence
     * are transferred into buffer <tt>dsts[offset]</tt>, up to the next
     * <tt>dsts[offset+1].remaining()</tt> bytes are transferred into buffer
     * <tt>dsts[offset+1]</tt>, and so forth, until the entire byte sequence
     * is transferred into the given buffers.  As many bytes as possible are
     * transferred into each buffer, hence the final position of each updated
     * buffer, except the last updated buffer, is guaranteed to be equal to
     * that buffer's limit.
     *
     * <p> This method may be invoked at any time.  If another thread has
     * already initiated a read operation upon this channel, however, then an
     * invocation of this method will block until the first operation is
     * complete. 

     *如果在当前线程读操作之前已经有线程在读通道,则必须等待当前读通道的线程完成,
     方可进程读操作。
     * @param  dsts
     *         The buffers into which bytes are to be transferred
     *
     * @param  offset
     *         The offset within the buffer array of the first buffer into
     *         which bytes are to be transferred; must be non-negative and no
     *         larger than <tt>dsts.length</tt>
     *
     * @param  length
     *         The maximum number of buffers to be accessed; must be
     *         non-negative and no larger than
     *         <tt>dsts.length</tt> - <tt>offset</tt>
     *
     * @return The number of bytes read, possibly zero,
     *         or <tt>-1</tt> if the channel has reached end-of-stream
     *
     * @throws  IndexOutOfBoundsException
     *          If the preconditions on the <tt>offset</tt> and <tt>length</tt>
     *          parameters do not hold
     *
     * @throws  NonReadableChannelException
     *          If this channel was not opened for reading
     *
     * @throws  ClosedChannelException
     *          If this channel is closed
     *
     * @throws  AsynchronousCloseException
     *          If another thread closes this channel
     *          while the read operation is in progress
     *
     * @throws  ClosedByInterruptException
     *          If another thread interrupts the current thread
     *          while the read operation is in progress, thereby
     *          closing the channel and setting the current thread's
     *          interrupt status
     *
     * @throws  IOException
     *          If some other I/O error occurs
     */
    public long read(ByteBuffer[] dsts, int offset, int length)
        throws IOException;

    /**
     * Reads a sequence of bytes from this channel into the given buffers.
     *此方法相当于read(dsts, 0, dsts.length)方法
     *  An invocation of this method of the form <tt>c.read(dsts)</tt>
     * behaves in exactly the same manner as the invocation
     *
     * <blockquote><pre>
     * c.read(dsts, 0, dsts.length);</pre></blockquote>
     *
     * @param  dsts
     *         The buffers into which bytes are to be transferred
     *
     * @return The number of bytes read, possibly zero,
     *         or <tt>-1</tt> if the channel has reached end-of-stream
     *
     * @throws  NonReadableChannelException
     *          If this channel was not opened for reading
     *
     * @throws  ClosedChannelException
     *          If this channel is closed
     *
     * @throws  AsynchronousCloseException
     *          If another thread closes this channel
     *          while the read operation is in progress
     *
     * @throws  ClosedByInterruptException
     *          If another thread interrupts the current thread
     *          while the read operation is in progress, thereby
     *          closing the channel and setting the current thread's
     *          interrupt status
     *
     * @throws  IOException
     *          If some other I/O error occurs
     */
    public long read(ByteBuffer[] dsts) throws IOException;
}
//
package java.nio.channels;
import java.io.IOException;
import java.nio.ByteBuffer;


/**
 * A channel that can write bytes from a sequence of buffers.
 *GatheringByteChannel可从一组缓冲区读取字节,写到通道中。
 * <p> A <i>gathering</i> write operation writes, in a single invocation, a
 * sequence of bytes from one or more of a given sequence of buffers.
 * Gathering writes are often useful when implementing network protocols or
 * file formats that, for example, group data into segments consisting of one
 * or more fixed-length headers followed by a variable-length body.  Similar
 * <i>scattering</i> read operations are defined in the {@link
 * ScatteringByteChannel} interface.  

 *
 *
 * @author Mark Reinhold
 * @author JSR-51 Expert Group
 * @since 1.4
 */

public interface GatheringByteChannel
    extends WritableByteChannel
{

    /**
     * Writes a sequence of bytes to this channel from a subsequence of the
     * given buffers.
     *从一组缓冲区读取字节,写到通道中。
     *  An attempt is made to write up to <i>r</i> bytes to this channel,
     * where <i>r</i> is the total number of bytes remaining in the specified
     * subsequence of the given buffer array, that is,
     *
     * <blockquote><pre>
     * srcs[offset].remaining()
     *     + srcs[offset+1].remaining()
     *     + ... + srcs[offset+length-1].remaining()</pre></blockquote>
     *
     * at the moment that this method is invoked.
     *
     * <p> Suppose that a byte sequence of length <i>n</i> is written, where
     * <tt>0</tt> <tt><=</tt> <i>n</i> <tt><=</tt> <i>r</i>.
     * Up to the first <tt>srcs[offset].remaining()</tt> bytes of this sequence
     * are written from buffer <tt>srcs[offset]</tt>, up to the next
     * <tt>srcs[offset+1].remaining()</tt> bytes are written from buffer
     * <tt>srcs[offset+1]</tt>, and so forth, until the entire byte sequence is
     * written.  As many bytes as possible are written from each buffer, hence
     * the final position of each updated buffer, except the last updated
     * buffer, is guaranteed to be equal to that buffer's limit.
     *
     * <p> Unless otherwise specified, a write operation will return only after
     * writing all of the <i>r</i> requested bytes.  Some types of channels,
     * depending upon their state, may write only some of the bytes or possibly
     * none at all.  A socket channel in non-blocking mode, for example, cannot
     * write any more bytes than are free in the socket's output buffer.
     *一些具体的通道,也许写一些字节,也许不写,依赖于具体的状态。非阻塞通道不能
     写比socket输出缓冲区多的字节数。
     * <p> This method may be invoked at any time.  If another thread has
     * already initiated a write operation upon this channel, however, then an
     * invocation of this method will block until the first operation is
     * complete. 

     *方法在一个进程中不能并发,一个读线程必须等另一个读线程完成,方可读取
     * @param  srcs
     *         The buffers from which bytes are to be retrieved
     *
     * @param  offset
     *         The offset within the buffer array of the first buffer from
     *         which bytes are to be retrieved; must be non-negative and no
     *         larger than <tt>srcs.length</tt>
     *
     * @param  length
     *         The maximum number of buffers to be accessed; must be
     *         non-negative and no larger than
     *         <tt>srcs.length</tt> - <tt>offset</tt>
     *
     * @return  The number of bytes written, possibly zero
     *
     * @throws  IndexOutOfBoundsException
     *          If the preconditions on the <tt>offset</tt> and <tt>length</tt>
     *          parameters do not hold
     *
     * @throws  NonWritableChannelException
     *          If this channel was not opened for writing
     *
     * @throws  ClosedChannelException
     *          If this channel is closed
     *
     * @throws  AsynchronousCloseException
     *          If another thread closes this channel
     *          while the write operation is in progress
     *
     * @throws  ClosedByInterruptException
     *          If another thread interrupts the current thread
     *          while the write operation is in progress, thereby
     *          closing the channel and setting the current thread's
     *          interrupt status
     *
     * @throws  IOException
     *          If some other I/O error occurs
     */
    public long write(ByteBuffer[] srcs, int offset, int length)
        throws IOException;


    /**
     * Writes a sequence of bytes to this channel from the given buffers.
     *与write(srcs, 0, srcs.length)等价
     * <p> An invocation of this method of the form <tt>c.write(srcs)</tt>
     * behaves in exactly the same manner as the invocation
     *
     * <blockquote><pre>
     * c.write(srcs, 0, srcs.length);</pre></blockquote>
     *
     * @param  srcs
     *         The buffers from which bytes are to be retrieved
     *
     * @return  The number of bytes written, possibly zero
     *
     * @throws  NonWritableChannelException
     *          If this channel was not opened for writing
     *
     * @throws  ClosedChannelException
     *          If this channel is closed
     *
     * @throws  AsynchronousCloseException
     *          If another thread closes this channel
     *          while the write operation is in progress
     *
     * @throws  ClosedByInterruptException
     *          If another thread interrupts the current thread
     *          while the write operation is in progress, thereby
     *          closing the channel and setting the current thread's
     *          interrupt status
     *
     * @throws  IOException
     *          If some other I/O error occurs
     */
    public long write(ByteBuffer[] srcs) throws IOException;

}

0
2
分享到:
评论

相关推荐

    java SocketChannel通信实例

    Selector是Java NIO中的选择器,它可以监控多个通道(包括SocketChannel)的状态变化,如连接就绪、读写就绪等。通过注册感兴趣的事件类型,Selector可以在这些事件发生时唤醒,避免了对每个通道进行单独的轮询检查...

    tcp.rar_SocketChannel_SocketChannel HTTPS_java socketchannel_非阻

    SocketChannel是java.nio.channels包下的一个接口,它代表了一个网络连接,可以用来读取和写入数据。与传统的Socket相比,SocketChannel提供了异步操作的能力,这意味着我们可以在不等待I/O操作完成的情况下继续执行...

    java的ServerSocketChannel与SocketChannel的使用

    Java的`ServerSocketChannel`和`SocketChannel`是NIO(非阻塞I/O)框架中的核心组件,它们为创建高性能、高并发的网络服务提供了基础。在Java中,传统的I/O模型基于流(Stream),而NIO则引入了通道(Channel)和...

    SocketChannel、ServerSocketChannel与Selector的实际案例

    它能够同时监视多个SocketChannel和ServerSocketChannel,当有读写事件发生时,Selector会返回这些通道的键(Keys),从而让我们的程序知道哪些通道准备好了进行I/O操作。这样,我们可以通过一个单线程处理多个连接...

    使用非阻塞ServerSocketChannel、SocketChannel代替ServerSocket和Socket

    SocketChannel是NIO中的客户端通道,用于与远程服务器通信。在服务器接收到客户端连接请求后,会返回一个新的SocketChannel实例。通过这个实例,我们可以进行读写操作。非阻塞模式下,`read()`和`write()`方法在数据...

    niossl:SSLSocketChannel和SSLServerSocketChannel实现

    NIO SSL 与阻塞IO不同,JVM不提供扩展基本套接字通道类的标准SSLSocketChannel和SSLServerSocketChannel类。 相反,必须使用手动编排SSL交换。 该项目提供了和,可以像和一样使用。入门直接下载您可以直接下载并将其...

    java通道处理程序

    Java中的通道包括FileChannel、SocketChannel、ServerSocketChannel等,分别用于文件操作、网络套接字通信和服务器套接字监听。 `ChannelDeal.java` 文件很可能是实现对这些通道进行管理、转换或者处理的类。在这个...

    TCP多通道通信

    5. **编程实现**:在编程中实现TCP多通道通信,可以利用套接字API(如Java的SocketChannel或C++的boost::asio库)来创建和管理多个通道。开发者需要关注如何正确地同步和协调这些通道,避免数据交错或冲突。 6. **...

    【IT十八掌徐培成】Java基础第27天-02.NIO-ServerSocketChannel-SocketChannel.zip

    通道是数据进出的路径,如FileChannel、SocketChannel、ServerSocketChannel等。它们提供了读写数据的方法,并且可以与Selector配合工作,实现高效的并发I/O操作。 7. **选择器模式(Selector Pattern)**: 通过...

    ProxiedSocketChannel:一个 Java SocketChannel 实现,它使用提供的 Proxy 实例通过提供的代理建立网络连接

    代理套接字通道 一个 Java SocketChannel 实现,它使用提供的 Proxy 实例通过提供的代理建立网络连接。 SocketChannel 是通过表面下的 Socket 实例实现的。 限制 此实现目前仅支持阻塞模式。 请注意,这是 ...

    Java NIO 系列教程1

    Java NIO中的主要通道包括FileChannel、DatagramChannel、SocketChannel和ServerSocketChannel,分别对应文件操作、UDP网络通信、TCP网络通信和服务器端的TCP连接。 4. **缓冲区(Buffer)** Java NIO提供了多种...

    笔记,4、深入Netty1

    `NioSocketChannel`继承自`AbstractNioByteChannel`,并实现了`ByteChannel`接口。它包含了对NIO的SocketChannel的包装,提供了一种更方便的方式来读写数据和管理通道状态。 3. **NioEventLoop**: 是Netty的事件...

    Nio和Io的详细描述.docx

    - **散播-聚集(Scatter-Gather)**:允许数据从一个缓冲区分散写入多个通道,或者从多个通道聚集到一个缓冲区。 - **通道间的传输(Channel to Channel Transfers)**:直接在两个通道之间传输数据,无需经过缓冲区...

    java多路复用socket客户端.

    Java NIO中的SocketChannel是一个连接到TCP网络套接字的通道。可以通过以下2种方式创建SocketChannel: 打开一个SocketChannel并连接到互联网上的某台服务器。 一个新连接到达ServerSocketChannel时,会创建一个...

    032002_【第20章:Java新IO】_通道(Channel)_java_hearing3oc_扣弄你澳大_stoppedh

    通道是Java NIO中连接到I/O设备(如文件、网络套接字、硬件设备等)的接口,它允许数据从源到目的地进行传输。 在Java NIO中,通道和缓冲区(Buffer)是两个核心概念。通道类似于传统IO中的流,但有以下几个显著...

    Java NIO(通道+缓冲区+选择器)

    Java NIO提供了多种通道,如FileChannel、SocketChannel、ServerSocketChannel和DatagramChannel。 2. **文件通道**:FileChannel主要用于与文件进行交互,可以通过RandomAccessFile、FileInputStream或...

    NIO编程技术指南_预览版

    分散读取和聚集写入是NIO的特性之一,允许将数据从多个缓冲区分散读取到通道,或者从通道聚集写入到多个缓冲区,这对于处理网络数据包或文件分块等场景非常有用。 8. **NIO与网络编程** 在网络编程中,NIO主要...

Global site tag (gtag.js) - Google Analytics