-2

Cant seem to find the answer to this in the java docs:

Does SocketChannel.read(ByteBuffer) append or overwrite the current ByteBuffer?

Verlix
  • 71
  • 4
  • 1
    `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.` – Sotirios Delimanolis Feb 24 '14 at 22:50

1 Answers1

2

The answer is in the Javadoc of ReadableByteChannel which SocketChannel implements:

An attempt is made to read up to r bytes from the channel, where r is the number of bytes remaining in the buffer, that is, dst.remaining(), at the moment this method is invoked.

Therefore, no, it does not overwrite.

fge
  • 119,121
  • 33
  • 254
  • 329