@Override
  public ByteBufferSharing wrap(ByteBuffer appData)
      throws IOException {
    try (final ByteBufferSharing outputSharing = outputBufferVendor.open()) {

      ByteBuffer myNetData = outputSharing.getBuffer();

      myNetData.clear();

      while (appData.hasRemaining()) {
        final SSLEngineResult wrapResult = engine.wrap(appData, myNetData);
        switch (wrapResult.getStatus()) {
          case BUFFER_OVERFLOW:
            final int newCapacity =
                myNetData.position() + engine.getSession().getPacketBufferSize();
            myNetData = outputSharing.expandWriteBufferIfNeeded(newCapacity);
            break;
          case BUFFER_UNDERFLOW:
          case CLOSED:
            throw new SSLException("Error encrypting data: " + wrapResult);
        }

        if (wrapResult.getHandshakeStatus() == NEED_TASK) {
          handleBlockingTasks();
        }
      }

      myNetData.flip();

      return outputBufferVendor.open();
    }
  }
This will throw an SSLHandshakeException if the handshake doesn't terminate in a FINISHED
state. It may throw other IOExceptions caused by I/O operations
geode-core/src/main/java/org/apache/geode/internal/net/NioSslEngine.java