private SSLEngineResult handshakeWrap(boolean doWrite) throws IOException {
    logger.trace("SSLHandshake handshakeWrap {}", getConnectionId());
    if (netWriteBuffer.hasRemaining()) {
      throw new IllegalStateException("handshakeWrap called with netWriteBuffer not empty");
    }
    //this should never be called with a network buffer that contains data
    //so we can clear it here.
    netWriteBuffer.clear();
    SSLEngineResult result = sslEngine.wrap(emptyBuf, netWriteBuffer);
    //prepare the results to be written
    netWriteBuffer.flip();
    handshakeStatus = result.getHandshakeStatus();
    if (result.getStatus() == Status.OK && result.getHandshakeStatus() == HandshakeStatus.NEED_TASK) {
      handshakeStatus = runDelegatedTasks();
    }
    if (doWrite) {
      flush(netWriteBuffer);
    }
    return result;
  }
Performs the WRAP function
@param doWrite boolean
@return SSLEngineResult
@throws IOException
ambry-network/src/main/java/com/github/ambry/network/SSLTransmission.java