code: void sendMessage(IMessage message) throws IOException, AvpDataException, NotInitializedException, ParseException {
  
      if (!isConnected()) {
        throw new IOException("Failed to send message over [" + socketDescription + "]");
      }
  
      //switch to wait for SSL handshake to workout.
      if (!isExchangeAllowed()) {
        //TODO: do more?
        return;
      }
  
      doTLSPreSendProcessing(message);
  
      final ByteBuffer messageBuffer = this.parser.encodeMessage(message);
      if (logger.isDebugEnabled()) {
        logger.debug("About to send a byte buffer of size [{}] over the TLS socket [{}]", messageBuffer.array().length, socketDescription);
      }
      lock.lock();
      try {
        this.outputStream.write(messageBuffer.array(), messageBuffer.position(), messageBuffer.limit());
        doTLSPostSendProcessing(message);
  
      } catch (Exception e) {
        logger.debug("Unable to send message", e);
        throw new IOException("Error while sending message: " + e);
      }
      finally {
        lock.unlock();
      }
  
      if (logger.isDebugEnabled()) {
        logger.debug("Sent a byte buffer of size [{}] over the TLS nio socket [{}]", messageBuffer.array().length, socketDescription);
      }
    }
docs: ---------------- helper methods ---------------------