Java/Eta/Core/src/main/java/com/refinitiv/eta/transport/CryptoHelper.java
final int write(final ByteBuffer src) throws IOException
    {
        checkEngine();
        // clear _appSendBuffer before using it
        _appSendBuffer.clear();

        // mark the src buffer so we can reset (src.reset()) if we want to indicate that nothing was read
        src.mark();

        // empty the source buffer src into _appSendBuffer
        int writeCount = 0;
        while (src.hasRemaining() && _appSendBuffer.hasRemaining())
        {
            _appSendBuffer.put(src.get());
            writeCount++;
        }

        // make _appSendBuffer readable
        _appSendBuffer.flip();

        // encrypt (wrap) the application plaintext (currently in _appSendBuffer)
        SSLEngineResult result = encryptApplicationData();

        // this checks whether the server side initiated key renegotiation and thus new handshake started
        if ((_engine.getHandshakeStatus() != HandshakeStatus.FINISHED) && (_engine.getHandshakeStatus() != HandshakeStatus.NOT_HANDSHAKING))
        {
            performHandshake();
        }

        // check how many bytes we've just used from the src buffer
        if (result.bytesConsumed() == 0)
        {
            // if we didn't consume any bytes, clear _appSendBuffer and reset src
            _appSendBuffer.clear();
            src.reset();

            return 0;
        }

        // return the number of bytes that we used from the src buffer.
        return writeCount;
    }
// (src should be immediately readable)
(src should be immediately readable)
( src should be immediately readable )
final int write(final ByteBuffer src) throws IOException
    {
        checkEngine();
        _appSendBuffer.clear();
        src.mark();
        int writeCount = 0;
        while (src.hasRemaining() && _appSendBuffer.hasRemaining())
        {
            _appSendBuffer.put(src.get());
            writeCount++;
        }
        _appSendBuffer.flip();
        SSLEngineResult result = encryptApplicationData();
        if ((_engine.getHandshakeStatus() != HandshakeStatus.FINISHED) && (_engine.getHandshakeStatus() != HandshakeStatus.NOT_HANDSHAKING))
        {
            performHandshake();
        }
        if (result.bytesConsumed() == 0)
        {
            _appSendBuffer.clear();
            src.reset();
            return 0;
        }
        return writeCount;
    }
final int write ( final ByteBuffer src ) throws IOException { checkEngine ( ) ; _appSendBuffer . clear ( ) ; src . mark ( ) ; int writeCount = 0 ; while ( src . hasRemaining ( ) && _appSendBuffer . hasRemaining ( ) ) { _appSendBuffer . put ( src . get ( ) ) ; writeCount ++ ; } _appSendBuffer . flip ( ) ; SSLEngineResult result = encryptApplicationData ( ) ; if ( ( _engine . getHandshakeStatus ( ) != HandshakeStatus . FINISHED ) && ( _engine . getHandshakeStatus ( ) != HandshakeStatus . NOT_HANDSHAKING ) ) { performHandshake ( ) ; } if ( result . bytesConsumed ( ) == 0 ) { _appSendBuffer . clear ( ) ; src . reset ( ) ; return 0 ; } return writeCount ; }
(src should be immediately readable)
( src should be immediately readable )
// clear _appSendBuffer before using it // mark the src buffer so we can reset (src.reset()) if we want to indicate that nothing was read // empty the source buffer src into _appSendBuffer // make _appSendBuffer readable // encrypt (wrap) the application plaintext (currently in _appSendBuffer) // this checks whether the server side initiated key renegotiation and thus new handshake started // check how many bytes we've just used from the src buffer // if we didn't consume any bytes, clear _appSendBuffer and reset src // return the number of bytes that we used from the src buffer.