【问题标题】:Java's SocketChannel.read(ByteBuffer)Java 的 SocketChannel.read(ByteBuffer)
【发布时间】:2014-02-24 22:49:18
【问题描述】:

似乎无法在 java 文档中找到答案:

SocketChannel.read(ByteBuffer) 是追加还是覆盖当前的ByteBuffer?

【问题讨论】:

  • Reads a sequence of bytes from this channel into the given buffer. Suppose that a byte sequence of length n is read, where 0 <= n <= r. This byte sequence will be transferred into the buffer so that the first byte in the sequence is at index p and the last byte is at index p + n - 1, where p is the buffer's position at the moment this method is invoked. Upon return the buffer's position will be equal to p + n; its limit will not have changed.

标签: java sockets bytebuffer socketchannel


【解决方案1】:

答案在 ReadableByteChannel 的 Javadoc 中,SocketChannel 实现了:

尝试从通道读取最多 r 个字节,其中 r 是在调用此方法时缓冲区中剩余的字节数,即 dst.remaining()。

因此,不,它不会覆盖。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-07-13
    • 1970-01-01
    • 1970-01-01
    • 2014-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多