title: How much data was transferred?
body: <p>When transmitting a file through socket in blocking mode</p>
  
  <pre><code>bytesTransferred = fileIChannel.transferTo(0, fileIChannel.size(), socketChannel);
  // or using a buffer
  ByteBuffer byteBuffer = ByteBuffer.allocateDirect(1024*8);
  while (fileIChannel.read(byteBuffer) != -1) {
  byteBuffer.flip();
  bytesTransferred += socketChannel.write(byteBuffer);
  byteBuffer.clear();
  </code></pre>
  
  <p>In the event of a connection failure, I need to keep the number of bytes transferred.
  I can do this by waiting for a response every from the server when it receives a particular number of bytes. Or, when the connection is restored, I send a request for the number of bytes received.
  Which of the options will be more correct? How is this problem usually resolved?</p>
  
  <p>And the second question. Is data integrity guaranteed when sending large data through a socket?</p>