code: private void writeFullBuffer(ByteBuffer buffer) throws IOException {
          int iterationsCount = MAX_WRITE_ITERATIONS;
          int writeCount;
          
          while(buffer.remaining() > 0 && iterationsCount > 0) {
              writeCount = _channel.write(buffer);
              if(writeCount == 0) {
                  // we decrement iterations count only when we could not write anything
                  --iterationsCount;
              } else {
                  // as long as we can write, we reset iterationsCount
                  iterationsCount = MAX_WRITE_ITERATIONS;
              }
          }
          
          if(buffer.remaining() > 0)
              throw new IOException("couldn't write the buffer after " + MAX_WRITE_ITERATIONS + " tries");
      }
docs: Writes the full content of the buffer to the channel. If this method exits normally
  (with no exception), then the buffer is entirely empty, ready to have more stuff written into it.
  
  @throws IOException