@Override
    public final OutputStream getOutputStream() throws IOException {
        checkOpen();

        OutputStream returnVal;
        synchronized (ssl) {
            if (state == STATE_CLOSED) {
                throw new SocketException("Socket is closed.");
            }

            if (os == null) {
                os = new SSLOutputStream();
            }

            returnVal = os;
        }

        // Block waiting for a handshake without a lock held. It's possible that the socket
        // is closed at this point. If that happens, we'll still return the output stream but
        // all writes on it will throw.
        waitForHandshake();
        return returnVal;
    }
Starts a TLS/SSL handshake on this connection using some native methods
from the OpenSSL library. It can negotiate new encryption keys, change
cipher suites, or initiate a new session. The certificate chain is
verified if the correspondent property in java.Security is set. All
listeners are notified at the end of the TLS/SSL handshake.
common/src/main/java/org/conscrypt/ConscryptFileDescriptorSocket.java