@Override
    protected void decode(ChannelHandlerContext context, ByteBuf in, List<Object> out) throws Exception {
        if (in.readableBytes() < SslUtils.SSL_RECORD_HEADER_LENGTH) {
            return;
        }
        if (SslHandler.isEncrypted(in)) {
            handleSsl(context);
        } else {
            handleNonSsl(context);
        }
    }
@Test
    public void handlerReplaced() throws Exception {
        final ChannelHandler nonSslHandler = Mockito.mock(ChannelHandler.class);
        OptionalSslHandler handler = new OptionalSslHandler(sslContext) {
            @Override
            protected ChannelHandler newNonSslHandler(ChannelHandlerContext context) {
                return nonSslHandler;
            }

            @Override
            protected String newNonSslHandlerName() {
                return HANDLER_NAME;
            }
        };
        final ByteBuf payload = Unpooled.copiedBuffer("plaintext".getBytes());
        try {
            handler.decode(context, payload, null);
            verify(pipeline).replace(handler, HANDLER_NAME, nonSslHandler);
        } finally {
            payload.release();
        }
    }